wqData['uniacid'], 'bonusPackage'); if (!$power) { echo json_encode(['code' => 2, 'msg' => '暂无权限']); die; } } public function actionIsPop() { $result=axios_request(); $res =(new \yii\db\Query()) ->from('{{%ybwm_dividend_join}}') ->where(['orderId'=>$result['orderId']])->one(); $divideset = Config::getSystemSet('divideset', $res['uniacid']); if ($res AND $divideset['isOpen'] == 1) { return $this->result(1, '成功', $res['id']); } else { return $this->result(2, '成功', 0); } } //瓜分红包详情 public function actionInfo() { $result=axios_request(); $userId=$this->wqData['userId']; $res =(new \yii\db\Query()) ->from('{{%ybwm_dividend_join}}') ->where(['id'=>$result['id']])->one(); if (!$res || $res['deleteAt'] > 0) { return $this->result(2, '该活动不存在'); } $list=(new \yii\db\Query()) ->select('b.userName,b.portrait,c.money,from_unixtime(a.createdAt)createdAt') ->from('{{%ybwm_dividend_receive}} as a') ->join('LEFT JOIN', '{{%ybwm_member}} as b', 'b.id = a.userId') ->join('LEFT JOIN', '{{%ybwm_user_coupon}} as c', 'c.id = a.couponId') ->where(['a.joinId'=>$result['id']])->all(); $receive = (new \yii\db\Query()) ->from('{{%ybwm_dividend_receive}}') ->where(['joinId'=>$result['id'],'userId' => $userId])->one(); $couponInfo = []; if ($receive) { $couponInfo = (new \yii\db\Query()) ->from('{{%ybwm_user_coupon}}') ->where(['id'=>$receive['couponId']])->one(); $couponInfo['endAt'] = date("Y-m-d", $couponInfo['endAt']); } $res['couponInfo'] = $couponInfo; $res['info'] = $list; return $this->result(1, '成功', $res); } //领取红包 public function doPagebonusPackage_receive() { $result=axios_request(); $request = Yii::$app->request; $userId=$this->wqData['userId']; $uniacid=$this->wqData['uniacid']; if ($request->isGet) { return $this->result(2, '请求异常'); } $res =(new \yii\db\Query()) ->from('{{%ybwm_dividend_join}}') ->where(['id'=>$result['id']])->one(); if (!$res || $res['deleteAt'] > 0) { return $this->result(2, '该活动不存在'); } $startToday = strtotime(date('Y-m-d', time())); $endToday = strtotime(date('Y-m-d', time())) + 3600 * 24; $receive = (new \yii\db\Query()) ->from('{{%ybwm_dividend_receive}}') ->where(['joinId'=>$result['id'],'userId' =>$userId])->one(); if ($receive) { return $this->result(2, '您已经领过了'); } $num = (new \yii\db\Query()) ->from('{{%ybwm_dividend_receive}}') ->where('createdAt>=:startTime AND createdAt<:endTime AND userId=:userId', [':startTime'=>$startToday,':endTime'=>$endToday,':userId'=>$userId])->all(); if ($res['surplusNum'] <= 0) { return $this->result(2, '红包已经抢完了'); } $divideset = Config::getSystemSet('divideset', $uniacid); if ($divideset['num'] <= count($num) AND $divideset['num'] > 0) { return $this->result(2, '今天领取次数超限'); } $couponIds = json_decode($res['couponIds'], true); $random_keys = array_rand($couponIds); $couponInfo = (new \yii\db\Query()) ->from('{{%ybwm_coupon}}') ->where(['uniacid'=>$uniacid,'id' =>$couponIds[$random_keys]])->one(); $startAt = $couponInfo['startAt']; $endAt = $couponInfo['endAt']; if ($couponInfo['timeType'] == 2) { $startAt = time(); $endAt = $startAt + $couponInfo['day'] * 24 * 3600; } if ($couponInfo['activityType'] == 1) { $useName = '全门店通用用'; } if ($couponInfo['activityType'] == 2) { $useName = '指定商户可用'; } if ($couponInfo['activityType'] == 6) { $useName = '指定商户可用'; } if ($couponInfo['activityType'] == 7) { $useName = '指定商品可用'; } if ($couponInfo['activityType'] == 8) { $useName = '指定分类可用'; } $userCoupon['couponId'] = $couponIds[$random_keys]; $userCoupon['userId'] = $userId; $userCoupon['startAt'] = $startAt; $userCoupon['endAt'] = $endAt; $userCoupon['isLimit'] = $couponInfo['isLimit']; $userCoupon['name'] = $couponInfo['name']; $userCoupon['full'] = $couponInfo['full']; $userCoupon['activityType'] = $couponInfo['activityType']; $userCoupon['item'] = $couponInfo['item'] == 1 ? json_encode(['1']) : $couponInfo['item']; $userCoupon['money'] = $couponInfo['money']; $userCoupon['useName'] = $useName; $userCoupon['introduce'] = $couponInfo['introduce']; $userCoupon['state'] = 1; $userCoupon['createdAt'] = time(); $userCoupon['uniacid'] = $uniacid; $rst =Yii::$app->db->createCommand()->insert('{{%ybwm_user_coupon}}', $userCoupon)->execute(); // $id = pdo_insertid(); // // if ($rst) { // pdo_update('ybcy_dividend_join', array('surplusNum -=' => 1), array('id' => $_GPC['id'])); // $data['joinId'] = $_GPC['id']; // $data['userId'] = $_GPC['userId']; // $data['couponId'] = $id; // $data['createdAt'] = time(); // $data['uniacid'] = $_W['uniacid']; // pdo_insert('ybcy_dividend_receive', $data); // $this->result(0, '成功'); // } } }