basePath . "/utils/Alipay/alipaySdk/aop/AopClient.php";; class PtOrderController extends BaseController { public function behaviors() { return parent::behaviors(); } public function actionCheckBuyer() { $goods_ids = input_params('goods_ids', []); $address_id = input_params('address_id', 0); if(empty($goods_ids) || empty($address_id)){ return $this->asJson([ 'code' => 1, 'msg' => '参数错误', ]); } $address = \app\models\Address::findOne($address_id); $res = \app\models\OrderRulesBuyerLocation::checkLocationGoodsList($goods_ids, $address, get_user_id()); return $this->asJson([ 'code' => 0, 'msg' => 'ok', 'data' => $res, ]); } /** * 新-订单提交前的预览页面 * @return \yii\web\Response */ public function actionSubmitPreview() { $form = new OrderSubmitPreviewForm(); $form->attributes = post_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->search()); } /** * 新-订单提交 * @return \yii\web\Response */ public function actionSubmit() { $form = new OrderSubmitForm(); $form->attributes = post_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); $form->user = get_user(); return $this->asJson($form->save()); } /** * 订单支付数据 * @return \yii\web\Response */ public function actionPayData() { $form = new OrderPayDataForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); $form->user = get_user(); return $this->asJson($form->search()); } /** * 订单列表 * @return \yii\web\Response */ public function actionList() { $form = new PtActivityOrderForm(); $form->attributes = get_params(); return $this->asJson($form->search()); } /** * 订单列表 * @return \yii\web\Response */ public function actionOrderInfo() { $form = new PtActivityOrderForm(); $form->attributes = get_params(); return $this->asJson($form->orderInfo()); } /** * 订单取消 * @return \yii\web\Response */ public function actionRevoke() { $form = new OrderRevokeForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->save()); } /** * 订单详情 * @return \yii\web\Response */ public function actionDetail() { $form = new OrderDetailForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); if (!empty(get_params('userId'))) { $form->user_id = get_params('userId'); } else { $form->user_id = get_user_id(); } return $this->asJson($form->search()); } /** * 获取核销码 * @return \yii\web\Response */ public function actionGetQrcode() { $order_no = get_params('order_no'); $order_type = get_params('order_type', ''); $page = "user/clerk/clerk"; if ($order_type) { $scene = "order_no:{$order_no},type:{$order_type}"; } else { $scene = "{$order_no}"; } if (is_wechat_platform()) { $file_name = ShareQrcode::wxQrcode($page,$scene); } if (is_alipay_platform()) { if ($order_type) { $scene = "order_no:{$order_no},type:{$order_type}"; } else { $scene = "order_no={$order_no}"; } $request = new AlipayOpenAppQrcodeCreateRequest(); $param = [ 'url_param' => 'user/clerk/clerk', 'query_param' => $scene, 'describe' => "小程序开发上线使用" ]; $aliConfigQr = $this->aliConfigQr($request, $param); $file_name['url_path'] = ""; if ($aliConfigQr->code === "10000") { $file_name['url_path'] = $aliConfigQr->qr_code_url_circle_blue; } } $res = [ 'code' => 0, 'msg' => 'success', 'data' => [ 'url' => $file_name['url_path'], ] ]; return $this->asJson($res); } /** * 订单确认收货 */ public function actionConfirm() { $form = new OrderConfirmForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->save()); } /** * 评论预览页面 */ public function actionCommentPreview() { $form = new OrderCommentPreview(); $form->attributes = get_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->search()); } /** * 评论提交 */ public function actionComment() { $form = new OrderCommentForm(); $form->attributes = post_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->save()); } /** * 售后页面 */ public function actionRefundPreview() { $form = new OrderRefundPreviewForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->search()); } /** * 售后订单列表 */ public function actionRefundList() { $form = new OrderListForm(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); $form->order_id = get_params('order_id'); $form->status = get_params('status'); return $this->asJson($form->getNewRefundList()); } /** * 售后订单列表 */ public function actionIntegralList() { $form = new OrderListForm(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->getIntegralList()); } /** * 售后提交 */ public function actionRefund() { $form = new OrderRefundForm(); $form->attributes = post_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->save()); } /** * 售后订单详情 */ public function actionRefundDetail() { $form = new OrderRefundDetailForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->search()); } /** * 售后订单取消 */ public function actionRefundCancel() { $order_refund_id = post_params('order_refund_id'); $orderRefund = OrderRefund::findOne(['id' => $order_refund_id, 'is_delete' => 0, 'store_id' => get_store_id()]); if (!$orderRefund) { return $this->asJson([ 'code' => 1, 'msg' => '订单不存在' ]); } if (in_array($orderRefund->status, [0, 3]) && $orderRefund->is_user_send == 0) { $orderRefund->is_user_cancel = 1; if ($orderRefund->save()) { return $this->asJson([ 'code' => 0, 'msg' => '取消成功' ]); } else { return $this->asJson([ 'code' => 1, 'msg' => $orderRefund->errors[0] ]); } } return $this->asJson([ 'code' => 1, 'msg' => '取消失败,当前订单在流程中' ]); } /** * 售后订单删除 */ public function actionRefundDelete() { $order_refund_id = post_params('order_refund_id'); $orderRefund = OrderRefund::findOne(['id' => $order_refund_id, 'is_delete' => 0, 'store_id' => get_store_id()]); if (!$orderRefund) { return $this->asJson([ 'code' => 1, 'msg' => '订单不存在' ]); } OrderRefund::updateAll(['user_delete' => 1], ['id' => $order_refund_id]); return $this->asJson([ 'code' => 0, 'msg' => '删除成功' ]); } /** * 全返订单列表 * @return \yii\web\Response */ public function actionQuanfan() { $form = new OrderListForm(); $form->attributes = get_params(); $form->store_id = $this->store_id; $form->user_id = get_user_id(); return $this->asJson($form->quanfan()); } /** * 售后订单用户发货 * @return \yii\web\Response */ public function actionRefundSend() { $form = new OrderRefundSendForm(); $form->attributes = post_params(); $form->user_id = get_user_id(); return $this->asJson($form->save()); } /** * 订单物流信息 */ 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()); } /** * saas订单列表 * @return \yii\web\Response */ public function actionSaas() { $form = new SaasOrderForm(); $form->attributes = get_params(); $form->user_id = get_user_id(); $form->status = get_params('status'); return $this->asJson($form->getList()); } /** * 同城配送预下单 * @return \yii\web\Response */ public function actionPreSubmitOrder() { $form = new OrderSubmitForm(); $form->attributes = post_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); $form->user = get_user(); return $this->asJson($form->preOrder()); } /** * 预取消订单 * @return \yii\web\Response */ public function actionPreCancelOrder() { $order_id = post_params('order_id'); $reason_id = post_params('reason_id', 5); $reason = post_params('reason', '其他原因'); $order = Order::findOne($order_id); if (!$order) { $this->asJson([ 'code' => 1, 'msg' => '订单不存在' ]); } if($order->alipay_trade_no){ $res = ADelivery::cancelOrder(1, get_store_id(), get_mini_id(), get_saas_user()->ali_user_id, $order->order_no, $reason_id, $reason);; return $res; } $result = Delivery::preCancelOrder($order->order_no, $reason_id, $reason); return $this->asJson($result); } /** * 取消订单 * @return \yii\web\Response */ public function actionCancelOrder() { $order_id = post_params('order_id'); $reason_id = post_params('reason_id', 5); $reason = post_params('reason', '其他原因'); $order = Order::findOne($order_id); if (!$order) { $this->asJson([ 'code' => 1, 'msg' => '订单不存在' ]); } if($order->alipay_trade_no){ $res = ADelivery::cancelOrder(0, get_store_id(), get_mini_id(), get_saas_user()->ali_user_id, $order->order_no, $reason_id, $reason);; return $res; } $result = Delivery::cancelOrder($order->order_no, $reason_id, $reason); return $this->asJson($result); } /** * @return \yii\web\Response */ public function actionUserDelete() { $order_id = post_params('order_id'); $order = Order::findOne(['id' => $order_id, 'user_delete' => 1]); if ($order) { return $this->asJson([ 'code' => 1, 'msg' => '订单已删除' ]); } Order::updateAll(['user_delete' => 1], ['id' => $order_id]); return $this->asJson([ 'code' => 0, 'msg' => '删除成功' ]); } public function actionFriendPay() { $order_id = post_params('order_id'); $order = Order::findOne(['id' => $order_id, 'is_delete' => 0]); \Yii::warning(['-------- 代付 -------', [$order_id, get_user_id()]]); if (get_user_id() != $order->user_id) { $order->pay_user_id = get_user_id(); $order->save(); } return $this->asJson([ 'code' => 0, 'msg' => 'success' ]); } public function aliConfigQr($request, $data = []) { try { $third_appid = Option::get("alipay_appid", 0, 'saas')['value']; $third_private_key = Option::get("alipay_app_private_key", 0, 'saas')['value']; $third_public_key = Option::get("alipay_public_key", 0, 'saas')['value']; $data = json_encode($data); $config_ali = Option::get(Option::OPTOPN_KEY, get_store_id(), 'alipay')['value']; $config_ali = json_decode($config_ali, true); $aop = new AopClient(); //如果商城的支付宝小程序信息存在,则使用支付宝小程序的配置信息 if (!empty($config_ali['app_id']) && !empty($config_ali['app_private_key']) && !empty($config_ali['app_public_key'])) { $aop->appId = $config_ali['app_id']; $aop->rsaPrivateKey = $config_ali['app_private_key']; $aop->alipayrsaPublicKey = $config_ali['app_public_key']; } else { //使用三方的配置信息 $aop->appId = $third_appid; $aop->rsaPrivateKey = $third_private_key; $aop->alipayrsaPublicKey = $third_public_key; $ali_mini = StoreAliMini::find()->where(['auth_app_id' => $config_ali['app_id'], 'is_cancel' => 0, 'store_id' => get_store_id()])->asArray()->one(); if (empty($ali_mini)) { throw new \Exception("查找小程序信息失败"); } $token = $ali_mini['auth_token']; } $aop->encryptType = "AES"; $aop->apiVersion = '1.0'; $aop->signType = 'RSA2'; $aop->postCharset = 'utf-8'; $aop->format = 'json'; $request->setBizContent($data); if (!empty($token)) { $result = $aop->execute ($request, null, $token); } else { $result = $aop->execute ($request); } $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; return $result->$responseNode; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } }