scenario = $form::SCENARIO_ADD; $form->attributes = $param; $form->store_id = get_store_id(); $res = $form->cashierUserAdd(); return $this->asJson($res); } /** * 搜索用户 * @return \yii\web\Response * User: hankaige * DATE TIME: 2022/12/6 15:50 */ public function actionSearchUser(){ $keyword = get_params('keyword'); if(empty($keyword)){ return $this->asJson(['code' => 0,'data'=>[]]); } if(substr($keyword, 0, 2) == '00'){ $keyword *= 1; $data = ['id' => $keyword, 'store_id' => get_store_id()]; } else { $data = ['AND', ['or',['like','binding',$keyword],['like','nickname',$keyword]], ['store_id' => get_store_id()]]; } $userList = User::find()->where($data)->orderBy('created_at DESC')->select('id,nickname,binding, user_label_id')->asArray()->all(); foreach ($userList as &$userItem) { $userLabel = UserLabel::getLabel(get_store_id(), $userItem['user_label_id']); $userItem['user_label_name'] = $userLabel->label_name ?: ''; } return $this->asJson(['code'=>0,'data'=>$userList]); } //获取对应商品的规格信息 public function actionGetGoodsAttr(){ $form = new GoodsForm(); $form->attributes = get_params(); $form->user_id = get_params('user_id',0); $form->store_id = get_store_id(); return $this->asJson($form->search()); } /** * 获取规格详情 * @return mixed */ public function actionGoodsAttrInfo() { $form = new GoodsAttrInfoForm(); $form->attributes = get_params(); return $this->asJson($form->search()); } /** * 申请挂单 * @return \yii\web\Response * User: hankaige * DATE TIME: 2022/12/5 15:06 */ public function actionHangingOrder(){ // 需要用户ID 挂单上皮ID $param = post_params(); $form = new HangingOrderForm(); $form->user_id = $param['user_id']; $form->store_id = get_store_id(); $form->md_id = get_md_id(); $form->goods_list = json_decode($param['goods_list'],true); $form->id = $param['id'] ?? 0; $res = $form->hangingOrder(); return $this->asJson($res); } /** * 获取挂单列表 可查询指定用户的挂单信息 * @return \yii\web\Response * User: hankaige * DATE TIME: 2022/12/6 09:29 */ public function actionGetHangingOrderList(){ $form = new HangingOrderForm(); $form->user_id = get_params('user_id',0); $form->order_no = get_params('order_no',''); $form->dateStart = get_params('dateStart',''); $form->dateEnd = get_params('dateEnd',''); $form->store_id = get_store_id(); $form->md_id = get_md_id(); $res = $form->getList(); return $this->asJson($res); } // 获取挂单订单商品 public function actionGetHangingOrderDetail(){ $form = new HangingOrderForm(); $form->goods_name = get_params('goods_name',''); $form->id = get_params('id'); $res = $form->getOrderDetail(); return $this->asJson($res); } /** * 删除挂单订单 * @return \yii\web\Response * User: hankaige * DATE TIME: 2022/12/6 09:36 */ public function actionDelHangingOrder(){ $form = new HangingOrderForm(); $form->id = get_params('id'); $res = $form->delHanging(); return $this->asJson($res); } /** * 删除挂单订单商品 * @return \yii\web\Response * User: hankaige * DATE TIME: 2022/12/6 14:16 */ public function actionDelHangingOrderDetail(){ $form = new HangingOrderForm(); $form->id = get_params('id'); $res = $form->delHangingOrderDetail(); return $this->asJson($res); } /** * 取出挂单 * @return \yii\web\Response * User: hankaige * DATE TIME: 2022/12/6 14:47 */ public function actionGetHangingOrder(){ $form = new HangingOrderForm(); $form->id = post_params('id'); $res = $form->getHangingOrder(); return $this->asJson($res); } //结算预览 public function actionOrderPreview(){ $form = new MchOrderSubmitPreviewForm(); $form->attributes = post_params(); $form->user_id = post_params('user_id'); $form->store_id = get_store_id(); $form->md_id = get_md_id(); return $this->asJson($form->search()); } // todo 生成待支付订单 public function actionSubmitOrder(){ $form = new MchOrderSubmitForm(); $form->attributes = post_params(); $form->user_id = post_params('user_id'); $form->store_id = get_store_id(); $form->md_id = get_md_id(); // $form->is_offline = 1; return $this->asJson($form->save()); } // todo 支付订单 public function actionPayData(){ $form = new MchOrderPayDataForm(); $form->attributes = post_params(); $form->user_id = post_params('user_id'); $form->store_id = get_store_id(); return $this->asJson($form->search()); } //订单列表 public function actionOrderList(){ $store_id = get_store_id(); $md_id = get_md_id(); $form = new OrderListForm(); $form->attributes = get_params(); $form->is_offline = Order::IS_OFFLINE_FALSE; $form->store_id = $store_id; $form->md_id = $md_id; //$form->order_id = get_params('order_id'); return $this->asJson($form->search()); } public function actionOrderRefund(){ // 获取订单 $store_id = get_store_id(); $form = new OrderListForm(); $form->attributes = get_params(); $form->is_offline = Order::IS_OFFLINE_FALSE; $form->store_id = $store_id; $form->order_id = get_params('order_id'); return $this->asJson($form->orderRefund()); } public function actionAddAddress() { $form = new UserForm(); $form->attributes = post_params(); $form->is_default = post_params('is_default', 0); $form->store_id = get_store_id(); return $this->asJson($form->addAddress()); } //修改购物车商品价格 public function actionSetGoodsPrice() { try { $goods_id = post_params('goods_id'); $attr_ = post_params('attr'); $price = post_params('price'); $user_id = post_params('user_id'); $md_id = post_params('md_id'); if (!$price || !$attr_) { throw new \Exception('修改价格失败,缺少规格或价格参数'); } $goods = Goods::findOne($goods_id); if ($goods) { $attr = json_decode($attr_, true); $attr_id = array_column($attr['attr_list'], 'attr_id'); sort($attr_id); $open = false; $goods_attr = json_decode($goods->attr, true); foreach ($goods_attr as &$attr_item) { $gods_attr_id = array_column($attr_item['attr_list'], 'attr_id'); sort($gods_attr_id); if (!array_diff($gods_attr_id, $attr_id)) { $open = true; } } if ($open) { $goods_price_log = new CashierGoodsPriceLog(); $goods_price_log->goods_id = $goods_id; $goods_price_log->attr = $attr_; $goods_price_log->price = $price; $goods_price_log->user_id = $user_id; $goods_price_log->md_id = $md_id; if (!$goods_price_log->save()) { throw new \Exception(json_encode($goods_price_log->errors, JSON_UNESCAPED_UNICODE)); } } else { throw new \Exception('修改价格失败,商品规格信息查询失败'); } } else { throw new \Exception('修改价格失败,商品信息未找到'); } return $this->asJson([ 'code' => 0, 'msg' => '设置成功' ]); } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } public function actionGetActionType(){ $result = CashierActionLog::TEXT; $result[0] = '全部'; return $this->asJson(['code' => 0,'data' => $result]); } public function actionGetActionLog() { $keyword = get_params('keyword'); $actionType = get_params('action_type'); $startTime = get_params('start_time'); $endTime = get_params('end_time'); $query = CashierActionLog::find()->alias('cal')->leftJoin(['u' => User::tableName()],'cal.user_id=u.id')->leftJoin(['su' => SaasUser::tableName()],'u.binding=su.mobile')->where(['cal.store_id' => get_store_id(), 'md_id' => get_md_id()]); if(!empty($keyword)){ $query->andWhere(['like','su.name',$keyword]); } if($actionType > 0){ $query->andWhere(['cal.action' => $actionType]); } if(!empty($startTime)){ $query->andWhere(['>','cal.created_at',$startTime]); } if(!empty($endTime)){ $query->andWhere(['<','cal.created_at',$endTime]); } $query->orderBy('cal.created_at DESC')->select('cal.*,su.name,su.avatar,su.mobile'); $result = pagination_make($query,true); foreach($result['list'] as &$item){ $item['created_at'] = date('Y-m-d H:i:s',$item['created_at']); $item['action_text'] = CashierActionLog::TEXT[$item['action']]; } return $this->asJson(['code' => 0,'data' => $result]); } public function actionGetReuseGoodsPrice(){ $form = new ReuseOrderGoodsPriceForm(); $form->user_id = post_params('user_id'); $form->goods_id = post_params('goods_id'); $form->store_id = get_store_id(); return $this->asJson($form->search()); } }