validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } $couponList = $this->getCouponList(); // $payTypeList = $this->getPayTypeList(); // Todo 暂时去掉支付类型,由客户端根据平台自动判断支付宝和微信 $payTypeList = []; $goods = $this->getGoods(); return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'coupon_list' => $couponList, 'payType_list' => $payTypeList, 'goods_id' => $goods->id, ], ]; } /** * 获取当面付优惠券 * @return array */ public function getCouponList() { // TODO: 如果加入联盟,就取联盟的优惠券,否则取当前store_id下的优惠券 $query = UserCoupon::find()->alias('uc') ->leftJoin(['c' => Coupon::tableName()], 'uc.coupon_id=c.id') ->leftJoin(['cas' => CouponAutoSend::tableName()], 'uc.coupon_auto_send_id=cas.id') ->where([ 'AND', ['uc.store_id' => $this->store_id], ['uc.is_delete' => 0], ['uc.is_use' => 0], ['uc.is_expire' => 0], ['uc.user_id' => $this->user_id], ]); if ($this->price) { $query->andWhere(['<=', 'c.min_price', $this->price]); } $list = $query->select('uc.id user_coupon_id,uc.is_use,uc.is_expire,c.rule,c.sub_price,c.min_price,cas.event,uc.begin_time,uc.end_time,uc.type,c.appoint_type,c.cat_id_list,c.goods_id_list') ->orderBy('c.sub_price DESC') ->asArray()->all(); $new_list = []; $events = [ 0 => '平台发放', 1 => '分享红包', 2 => '购物返券', 3 => '领券中心', ]; \Yii::error($list); foreach ($list as $i => $item) { if ($item['begin_time'] > (strtotime(date('Y-M-d')) + 86400) || $item['end_time'] < time()) { continue; } $list[$i]['status'] = 0; if ($item['is_use']) { $list[$i]['status'] = 1; } if ($item['is_expire']) { $list[$i]['status'] = 2; } $list[$i]['min_price_desc'] = $item['min_price'] == 0 ? '无门槛' : '满' . $item['min_price'] . '元可用'; $list[$i]['begin_time'] = date('Y.m.d H:i', $item['begin_time']); $list[$i]['end_time'] = date('Y.m.d H:i', $item['end_time']); if (!$item['event']) { if ($item['type'] == 2) { $list[$i]['event'] = $item['event'] = 3; } else { $list[$i]['event'] = $item['event'] = 0; } } $list[$i]['event_desc'] = $events[$item['event']]; $list[$i]['min_price'] = doubleval($item['min_price']); $list[$i]['sub_price'] = doubleval($item['sub_price']); if ($this->price < $list[$i]['min_price']) { unset($list[$i]); continue; } $new_list[] = $list[$i]; } return $new_list; } /** * 获取支付类型 * @return array */ protected function getPayTypeList() { // TODO: store_id mch $setting = ScanCodePaySetting::findOne(['store_id' => $this->store_id, 'mch' => 0, 'is_delete' => 0]); $paymentType = json_decode($setting['payment_type'], true); $payType = []; $payType[] = [ 'name' => '微信支付', 'payment' => 1, 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-online.png' ]; foreach ($paymentType as $key => $value) { if ($key == 'wechat' && $value == 0) { $payType = []; } if ($key == 'balance' && $value == 1) { $balance = Option::get('payment', $this->store_id, 'store'); $balance = json_decode($balance['value'], true); if ($balance && $balance['balance']['value'] == 1) { $payType[] = [ 'name' => '账户余额支付', 'payment' => 3, 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-balance.png' ]; } } } return $payType; } /** * 获取当面付商品 */ protected function getGoods() { $goods = Goods::find()->where([ 'is_delete' => 0, 'store_id' => $this->store_id, 'type' => 6, ])->one(); if (!$goods) { $goods = new Goods(); $goods->store_id = $this->store_id; $goods->name = '当面付'; $goods->detail = '
当面付
'; $goods->created_at = time(); $goods->attr = '[{"attr_list":[{"attr_id":1,"attr_name":"默认"}],"num":0,"price":0,"no":"","pic":"","share_commission_first":"","share_commission_second":"","share_commission_third":""}]'; $goods->cover_pic = 'https://chidian.cyyvip.com/web/statics/images/scan-code-pay/goods_pic.png'; $goods->full_cut = '{"pieces":"","forehead":""}'; $goods->integral = '{"give":"0","forehead":"","more":""}'; $goods->use_attr = 0; $goods->quick_purchase = 0; $goods->hot_cakes = 0; $goods->type = 6; $goods->save(); } return $goods; } }