attributes = get_params(); if (!empty(get_params('is_offline')) && get_params('is_offline') == Order::IS_OFFLINE_TRUE) { $form->is_offline = Order::IS_OFFLINE_TRUE; } else { $form->is_offline = Order::IS_OFFLINE_FALSE; } $form->store_id = $store_id; $form->order_id = get_params('order_id'); return $this->asJson($form->search()); } /** * 平台商品订单取消 */ public function actionApplyOrderDelete() { $store_id = get_store_id(); $where = [ 'id' => post_params('id'), 'is_delete' => Order::IS_DELETE_FALSE, 'store_id' => $store_id, 'mch_id' => 0, ]; // type=1 后台主要取消订单, type=0 用户发起订单取消申请 if (post_params('type') == Order::CANCEL_USER_TYPE) { $where['apply_delete'] = Order::ORDER_APPLY_DELETE; } $order = Order::findOne($where); if (!$order || $order->mch_id > 0) { return $this->asJson([ 'code' => 1, 'msg' => '订单不存在,请刷新页面后重试' ]); } // 发送备注消息 $order->remark = post_params('remark', ''); // 同意 if (post_params('status') == 1) { $form = new OrderRevokeForm(); $form->order_id = $order->id; $form->delete_pass = true; $form->user_id = $order->user_id; $form->store_id = $order->store_id; $res = $form->save(); if ($res['code'] == 0) { $order->save(); $goods = Goods::findOne(OrderDetail::findOne(['order_id' => $order->id])->goods_id); NoticeSend::OrderCancel($order->user_id, $order->mobile, $order->order_no, $order->pay_price, $goods->name, 1); // 订单打印 if ((int)$order->md_id === -1 || (int)$order->md_id === 0 || !isset($order->md_id)) { $order->md_id = 0; } $printer_order = new PrintOrder($order->store_id, $order->id, 'confirm', 0, $order->md_id); $printer_order->is_refund = true; $printer_order->print_order(); return $this->asJson([ 'code' => 0, 'msg' => '操作成功', ]); } else { return $this->asJson($res); } } else { //拒绝 $order->apply_delete = Order::ORDER_APPLY_DELETE_DEFAULT; $order->save(); // TODO :推送订单取消拒绝消息 return $this->asJson([ 'code' => 0, 'msg' => '操作成功', ]); } } /** * 添加备注 */ public function actionSellerComments() { $store_id = get_store_id(); $order_id = get_params('order_id'); $seller_comments = get_params('seller_comments'); $form = Order::find()->where(['store_id' => $store_id, 'id' => $order_id, 'mch_id' => get_mch_id()])->one(); $form->seller_comments = $seller_comments; if ($form->save()) { return $this->asJson([ 'code' => 0, 'msg' => '操作成功', ]); } else { return $this->asJson([ 'code' => 1, 'msg' => '操作失败', ]); } } /** * 添加商家留言 */ public function actionSetWords() { $store_id = get_store_id(); $order_id = post_params('order_id'); $words = post_params('words'); $form = Order::find()->where(['store_id' => $store_id, 'id' => $order_id, 'mch_id' => get_mch_id()])->one(); $form->words = $words; if ($form->save()) { return $this->asJson([ 'code' => 0, 'msg' => '操作成功', ]); } else { return $this->asJson([ 'code' => 1, 'msg' => '操作失败', ]); } } /** * 更新订单地址 * @return \yii\web\Response */ public function actionSetOrderAddress() { $commonUpdateAddress = new CommonUpdateAddress(); $commonUpdateAddress->data = post_params(); $updateAddress = $commonUpdateAddress->updateAddress(); return $this->asJson($updateAddress); } /** * 售后订单列表 */ public function actionRefund() { $form = new OrderRefundListForm(); $form->attributes = \Yii::$app->request->get(); $form->attributes = \Yii::$app->request->post(); $form->store_id = get_store_id(); return $this->asJson($form->search()); } /** * 处理售后订单 */ public function actionRefundHandle() { $form = new OrderRefundForm(); $form->attributes = post_params(); $form->store_id = get_store_id(); return $this->asJson($form->save()); } /** * 商品评论列表 */ public function actionCommentList() { $form = new OrderCommentForm(); $form->store_id = get_store_id(); return $this->asJson($form->getComment()); } /** * 评论回复 */ public function actionCommentReply() { $form = new OrderCommentForm(); $form->id = post_params('id'); $form->reply_content = post_params('reply_content'); $form->store_id = get_store_id(); return $this->asJson($form->reply()); } /** * 评论显示隐藏 */ public function actionCommentHide() { $form = new OrderCommentForm(); $form->id = post_params('id'); $form->status = post_params('status'); $form->store_id = get_store_id(); return $this->asJson($form->hideStatus()); } /** * 评论删除 */ public function actionCommentDelete() { $form = new OrderCommentForm(); $form->id = post_params('id'); $form->status = post_params('status'); $form->store_id = get_store_id(); return $this->asJson($form->deleteStatus()); } /** * @return array|string */ public function actionCommentEdit() { $store_id = get_store_id(); $form = new OrderCommentForm(); $pic_list = array(); if (!empty(post_params('pic_list'))) { if (count(post_params('pic_list')) > 6) { return $this->asJson( [ 'code' => 1, 'msg' => '图片最多为6张' ] ); } foreach (post_params('pic_list') as $item) { $pic_list[] = Html::encode($item); } } $form->pic_list = json_encode($pic_list); if (json_encode($pic_list) === '[""]') { $form->pic_list = '[]'; } $form->store_id = $store_id; $form->attributes = post_params(); $created_at = post_params('created_at'); $form->created_at = $created_at ? strtotime($created_at) : time(); return $this->asJson($form->save()); } /** * 订单发货 * @return mixed */ public function actionSend() { $form = new OrderSendForm(); $post = post_params(); if ($post['is_express'] == OrderSendForm::EXPRESS_TYPE_EXPRESS) { $form->scenario = 'EXPRESS'; }elseif ($post['is_express'] == OrderSendForm::EXPRESS_TYPE_DADA){ $form->scenario = 'DADA'; }elseif ($post['is_express'] == OrderSendForm::EXPRESS_TYPE_UU){ $form->scenario = 'UU'; }elseif ($post['is_express'] == OrderSendForm::EXPRESS_TYPE_PEISONG){ $form->scenario = 'PEISONG'; } $form->attributes = $post; $form->store_id = get_store_id(); return $this->asJson($form->cost_order_save()); } /** * 货到付款 确认收货 * @return \yii\web\Response */ public function actionConfirm() { $store_id = get_store_id(); $order_id = post_params('order_id'); $order = Order::findOne([ 'id' => $order_id, 'mch_id' => 0, 'store_id' => $store_id ]); if (!$order) { return $this->asJson([ 'code' => 1, 'msg' => '订单不存在,请刷新重试', ]); } if ($order->pay_type != 2) { return $this->asJson([ 'code' => 1, 'msg' => '订单支付方式不是货到付款,无法确认收货', ]); } if ($order->trade_status != Order::ORDER_FLOW_SEND) { return $this->asJson([ 'code' => 1, 'msg' => '订单未发货', ]); } $order->trade_status = Order::ORDER_FLOW_CONFIRM; $order->confirm_time = time(); $order->is_pay = Order::IS_PAY_TRUE; $order->pay_time = time(); if ($order->save()) { return $this->asJson([ 'code' => 0, 'msg' => '成功', ]); } else { return $this->asJson([ 'code' => 1, 'msg' => $order->errors[0], ]); } } /** * 小票打印 * @return mixed */ public function actionPrintOrder() { $data = post_params(); $store_id = get_store_id(); $md_id = get_md_id(); // 订单打印 if ((int)$md_id === -1 || (int)$md_id === 0 || !isset($order->md_id)) { $md_id = 0; } $print = new PrintOrder($store_id, $data['order_id'], 'reprint', $data['order_type'], $md_id ); return $this->asJson($print->print_order()); } /** * 订单打印 */ public function actionPrint() { $id = \Yii::$app->request->get('id'); $express = \Yii::$app->request->get('express'); $post_code = \Yii::$app->request->get('code'); $form = new PrintExpress(); $form->store_id = get_store_id(); $form->order_id = $id; $form->express = $express; $form->post_code = $post_code; return $this->asJson($form->send()); } /** * 核销订单 * @return mixed */ public function actionClerk() { $form = new OrderClerkForm(); $form->attributes = post_params(); $form->order_model = 'app\models\Order'; $form->store_id = get_store_id(); return $this->asJson($form->clerk()); } /** * 修改价格 * @return mixed */ public function actionModifyPrice() { $form = new OrderPriceForm(); $form->attributes = post_params(); $form->store_id = get_store_id(); return $this->asJson($form->save()); } /** * 移入回收站 */ public function actionEdit() { $order_id = get_params('order_id'); $is_recycle = get_params('is_recycle'); if ($is_recycle == 0 || $is_recycle == 1) { $form = Order::find()->where(['store_id' => get_store_id(), 'mch_id' => 0]) ->andWhere('id = :order_id', [':order_id' => $order_id])->one(); $form->is_recycle = $is_recycle; if ($form && $form->save()) { return $this->asJson([ 'code' => 0, 'msg' => '操作成功', ]); } }; return $this->asJson([ 'code' => 1, 'msg' => '操作失败', ]); } /** * 订单物流信息 */ public function actionExpressDetail() { $form = new ExpressDetailForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->search()); } /** * 修改自提点 */ public function actionUpdateShop() { $form = new OrderShopForm(); $form->order_id = get_params('order_id'); $form->shop_id = get_params('shop_id'); $form->goods_id = get_params('goods_id'); return $this->asJson($form->save()); } /** * 是否认养成熟 * @return \yii\web\Response */ public function actionOrderMature() { $store_id = get_store_id(); $order_id = post_params('order_id'); $order = Order::findOne([ 'id' => $order_id, 'mch_id' => 0, 'store_id' => $store_id ]); $adopt_order = AdoptOrderInfo::findOne([ 'order_id' => $order_id, 'store_id' => $store_id, ]); if (!$order || !$adopt_order) { return $this->asJson([ 'code' => 1, 'msg' => '订单不存在,请刷新重试', ]); } // if ($order->trade_status != Order::ORDER_FLOW_SEND) { // return $this->asJson([ // 'code' => 1, // 'msg' => '订单未发货', // ]); // } // $order->trade_status = Order::ORDER_FLOW_CONFIRM; $adopt_order->is_mature = 1; $adopt_order->mature_time = time(); if ($adopt_order->save()) { $goods = Goods::findOne(OrderDetail::findOne(['order_id' => $order_id])->goods_id); NoticeSend::AdoptOrderStateChange($order->user_id, $adopt_order->mobile, $order->order_no, $goods->name, 1); return $this->asJson([ 'code' => 0, 'msg' => '修改成功', ]); } else { return $this->asJson([ 'code' => 1, 'msg' => $adopt_order->errors[0], ]); } } /** * 是否入库 * @return \yii\web\Response */ public function actionOrderStorage() { $store_id = get_store_id(); $order_id = post_params('order_id'); $harvest_weight = post_params('harvest_weight'); $harvest_storage_pic_url = post_params('harvest_storage_pic_url'); $order = Order::findOne([ 'id' => $order_id, 'mch_id' => 0, 'store_id' => $store_id ]); $adopt_order = AdoptOrderInfo::findOne([ 'order_id' => $order_id, 'store_id' => $store_id, ]); if (!$order || !$adopt_order) { return $this->asJson([ 'code' => 1, 'msg' => '订单不存在,请刷新重试', ]); } if ($adopt_order->is_mature == 0) { return $this->asJson([ 'code' => 1, 'msg' => '认养未成熟,不能入库', ]); } // if ($order->trade_status != Order::ORDER_FLOW_SEND) { // return $this->asJson([ // 'code' => 1, // 'msg' => '订单未发货', // ]); // } // $order->trade_status = Order::ORDER_FLOW_CONFIRM; $adopt_order->is_storage = 1; $adopt_order->storage_time = time(); $adopt_order->harvest_weight = $harvest_weight; $adopt_order->harvest_storage_pic_url = $harvest_storage_pic_url; if ($adopt_order->save()) { $goods = Goods::findOne(OrderDetail::findOne(['order_id' => $order_id])->goods_id); NoticeSend::AdoptOrderStateChange($order->user_id, $adopt_order->mobile, $order->order_no, $goods->name, 10); return $this->asJson([ 'code' => 0, 'msg' => '成功', ]); } else { return $this->asJson([ 'code' => 1, 'msg' => $adopt_order->errors[0], ]); } } /** * 订单额外费用 */ public function actionOrderExtraFee() { $store_id = get_store_id(); $order_id = post_params('order_id'); $other_pick_fee = post_params('other_pick_fee'); $preserve_fee = post_params('preserve_fee'); $form = AdoptOrderInfo::find()->where(['store_id' => $store_id, 'order_id' => $order_id])->one(); $form->other_pick_fee = $other_pick_fee ? $other_pick_fee : []; $form->preserve_fee = $preserve_fee ? $preserve_fee : []; if ($form->save()) { return $this->asJson([ 'code' => 0, 'msg' => '操作成功', ]); } else { return $this->asJson([ 'code' => 1, 'msg' => '操作失败', ]); } } /** * 是否确认自采完成 * @return \yii\web\Response */ public function actionOrderConfirmSelfPick() { $store_id = get_store_id(); $order_id = post_params('order_id'); $order = Order::findOne([ 'id' => $order_id, 'mch_id' => 0, 'store_id' => $store_id ]); $adopt_order = AdoptOrderInfo::findOne([ 'order_id' => $order_id, 'store_id' => $store_id, ]); if (!$order || !$adopt_order) { return $this->asJson([ 'code' => 1, 'msg' => '订单不存在,请刷新重试', ]); } if($adopt_order->end_self_pick == 0) { return $this->asJson([ 'code' => 1, 'msg' => '用户未确认自采完成,您还不能确认自采完成', ]); } $adopt_order->confirm_self_pick = 1; $adopt_order->confirm_self_pick_time = time(); if ($adopt_order->save()) { $goods = Goods::findOne(OrderDetail::findOne(['order_id' => $order_id])->goods_id); NoticeSend::AdoptOrderStateChange($order->user_id, $adopt_order->mobile, $order->order_no, $goods->name, 7); // $order->trade_status = Order::ORDER_FLOW_CONFIRM; // // if ($order->save()) { // return $this->asJson([ // 'code' => 0, // 'msg' => '修改成功', // ]); // }else { // return $this->asJson([ // 'code' => 1, // 'msg' => $order->errors[0], // ]); // } return $this->asJson([ 'code' => 0, 'msg' => '修改成功', ]); } else { return $this->asJson([ 'code' => 1, 'msg' => $adopt_order->errors[0], ]); } } /** * 是否确认自采预约 * @return \yii\web\Response */ public function actionOrderConfirmSelfPickBook() { $store_id = get_store_id(); $order_id = post_params('order_id'); $order = Order::findOne([ 'id' => $order_id, 'mch_id' => 0, 'store_id' => $store_id ]); $adopt_order = AdoptOrderInfo::findOne([ 'order_id' => $order_id, 'store_id' => $store_id, ]); if (!$order || !$adopt_order) { return $this->asJson([ 'code' => 1, 'msg' => '订单不存在,请刷新重试', ]); } $adopt_order->confirm_self_pick_book = 1; $adopt_order->confirm_self_pick_book_time = time(); if ($adopt_order->save()) { $goods = Goods::findOne(OrderDetail::findOne(['order_id' => $order_id])->goods_id); NoticeSend::AdoptOrderStateChange($order->user_id, $adopt_order->mobile, $order->order_no, $goods->name, 4); return $this->asJson([ 'code' => 0, 'msg' => '修改成功', ]); } else { return $this->asJson([ 'code' => 1, 'msg' => $adopt_order->errors[0], ]); } } }