basePath . "/utils/Alipay/alipaySdk/aop/AopClient.php";; class OrderController extends BaseController { public function behaviors() { return parent::behaviors(); } public function actionCheckBuyer() { $goods_ids = input_params('goods_ids', []); $is_shop = input_params('isShop', false); $address_id = input_params('address_id', 0); $is_giving_gifts = input_params('is_giving_gifts', 0); if($is_giving_gifts){ return $this->asJson([ 'code' => 0, 'msg' => 'ok', ]); } if(empty($goods_ids)){ return $this->asJson([ 'code' => 1, 'msg' => '参数错误', ]); } $goods_id = array_column($goods_ids, 'goods_id'); if (empty($goods_id)) { $goods_id = $goods_ids; } if (!$is_shop) { $address = \app\models\Address::findOne($address_id); } $res = \app\models\OrderRulesBuyerLocation::checkLocationGoodsList($goods_id, $address, get_user_id()); if (!$res) { $is_worker = false; //拼装goods_list数据 $goods_list = []; foreach ($goods_ids as $goods_id_item) { $goods = Goods::findOne($goods_id_item['goods_id'] ?? $goods_id_item); if (intval($goods->product_type) === Goods::GOODS_TYPE_WORKER) { $is_worker = true; } $goods_list[] = [ 'freight' => $goods->freight, 'num' => $goods_id_item['num'] ?? 1, 'weight' => $goods->weight * ($goods_id_item['num'] ?? 1), 'goods_id' => $goods->id, ]; } $res = null; if ($address) { PostageRules::getExpressPriceMore(get_store_id(), $address->city_id, $goods_list, $address->province_id, $res); } if ($is_worker) { $res = null; } foreach ($goods_ids as $goods_id_item) { //是否可以购买超级卖货活动产品 if (!SuperSales::canSuperSalesOrder(get_user_id(), $goods_id_item['goods_id'] ?? $goods_id_item, get_store_id(), $error_msg)) { $res[$goods_id_item['goods_id'] ?? $goods_id_item] = [ 'status' => false, 'msg' => $error_msg, ]; }; } } return $this->asJson([ 'code' => 0, 'msg' => 'ok', 'data' => $res, ]); } /** * 转换mch_list */ public function actionFilterMchList() { $form = new OrderSubmitPreviewForm(); $form->attributes = all_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->filter_mch_list()); } /** * 新-订单提交前的预览页面 * @return \yii\web\Response */ public function actionSubmitPreview() { $form = new OrderSubmitPreviewForm(); $form->attributes = post_params(); $form->send = post_params('send',''); $form->store_id = get_store_id(); $form->user_id = get_user_id(); $result = $form->search(); if ($result['code']) { //需求:失败的话 需要让用户选择返回上一页 还是返回购物车 兼容前端 $result['code'] = 400; } return $this->asJson($result); } /** * 新-订单提交 * @return \yii\web\Response */ public function actionSubmit() { $form = new OrderSubmitForm(); $form->attributes = post_params(); $form->send_price = post_params('send_price'); $form->take_price = post_params('take_price'); $form->balance = post_params('balance'); $form->store_id = get_store_id(); $form->user_id = get_user_id(); $form->user = get_user(); $result = $form->save(); if ($result['code']) { //需求:失败的话 需要让用户选择返回上一页 还是返回购物车 兼容前端 $result['code'] = 400; } return $this->asJson($result); } /** * 订单支付数据 * @return \yii\web\Response */ public function actionPayData() { $form = new OrderPayDataForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); $form->user = get_user(); $result = $form->search(); if ($result['code']) { //需求:失败的话 需要让用户选择返回上一页 还是返回购物车 兼容前端 $result['code'] = 400; } return $this->asJson($result); } /** * 货到付款订单支付 * @return void * User: hankaige * DATE TIME: 2022/12/30 15:24 */ public function actionMeetPayData(){ $form = new OrderPayDataForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); $form->user = get_user(); return $this->asJson($form->meetOrderPay()); } public function actionGiftsReceivedAddr() { $form = new OrderSubmitForm(); $form->attributes = all_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); $form->user = get_user(); $result = $form->giftsReceivedAddr(all_params()); if ($result['code']) { //需求:失败的话 需要让用户选择返回上一页 还是返回购物车 兼容前端 $result['code'] = 400; } return $this->asJson($result); } /** * 订单列表 * @return \yii\web\Response */ public function actionList() { $form = new OrderListForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->search(all_params())); } /** * 订单取消 * @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 mixed */ public function actionModifyPrice() { $form = new OrderPriceForm(); $form->attributes = post_params(); $form->store_id = get_store_id(); return $this->asJson($form->save()); } /** * 获取核销码 * @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}"; } $file_name = [ 'url_path' => '' ]; if (is_wechat_platform()) { $file_name = ShareQrcode::wxQrcode($page,$scene); } if (is_alipay_platform()) { $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; } } if (is_h5() || is_app_platform()) { $fileName = md5('user/clerk/clerk' . $scene.get_store_id()); // 保存小程序码到文件 $dir = \Yii::$app->runtimePath . '/image/wx_qrcode'; if (! is_dir($dir)) { mkdir($dir, 0777, true); } $file_name['url_path'] = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/wx_qrcode/' . $fileName. '.jpg'); QrCode::image(\Yii::$app->request->hostInfo . '/h5/#/user/clerk/clerk?scene='.$scene, 600, false, 'L', 'JPEG', 0, ['255,255,255', '0,0,0'], 1, false, $dir. '/' .$fileName . '.jpg'); } $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() { $t = \Yii::$app->db->beginTransaction(); try { $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()) { throw new \Exception($orderRefund->errors[0]); } $merchant = new MerchantForm(); $result = $merchant->orderRefundCancel($orderRefund->order_id); if ($result['code']) { throw new \Exception($result['msg']); } $t->commit(); return $this->asJson([ 'code' => 0, 'msg' => '取消成功' ]); } throw new \Exception('取消失败,当前订单在流程中'); } catch (\Exception $e) { $t->rollBack(); return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } /** * 售后订单删除 */ 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(); $form->pre_order_data = post_params('data'); $result = $form->preOrder(); if ($result['code']) { //需求:失败的话 需要让用户选择返回上一页 还是返回购物车 兼容前端 $result['code'] = 400; } return $this->asJson($result); } /** * 预取消订单 * @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' => '订单不存在' ]); } $delivery = \app\models\DeliveryKeloop::findOne(['order_no' => $order->order_no, 'store_id' => $order->store_id]); if($delivery && KeloopForm::isSaasOpen()){ return $this->asJson([ 'code' => 0, 'msg' => '预取消订单', 'data' => [ 'resultcode' => 0, ], ]); } $delivery = \app\models\DeliveryMaiyatian::findOne(['order_no' => $order->order_no, 'store_id' => $order->store_id]); if($delivery && MaiyatianForm::isopen(get_store_id())){ return $this->asJson([ 'code' => 0, 'msg' => '预取消订单', 'data' => [ 'resultcode' => 0, ], ]); } $delivery = \app\models\DeliveryInfo::findOne(['order_no' => $order->order_no, 'store_id' => $order->store_id]); if($delivery['is_local'] == 1){ if($delivery['local_status'] > 0){ return $this->asJson([ 'code' => 1, 'msg' => '预取消订单失败,原因:已经开始配送', 'data' => [ 'resultcode' => 0, ], ]); } return $this->asJson([ 'code' => 0, 'msg' => '预取消订单', 'data' => [ 'resultcode' => 0, ], ]); } 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' => '订单不存在' ]); } $delivery = \app\models\DeliveryKeloop::findOne(['order_no' => $order->order_no, 'store_id' => $order->store_id]); if($delivery && KeloopForm::isSaasOpen()){ $reason = Delivery::$validReason[$reason_id]; $res = KeloopForm::order_canceled(get_store_id(), $order_id, $reason, 1); $res['data']['resultcode'] = $res['code']; return $this->asJson($res); } $delivery = \app\models\DeliveryMaiyatian::findOne(['order_no' => $order->order_no, 'store_id' => $order->store_id]); if($delivery && MaiyatianForm::isopen(get_store_id())){ $reason = Delivery::$validReason[$reason_id]; $res = MaiyatianForm::order_canceled(get_store_id(), $order_id, $reason, 1); $res['data']['resultcode'] = $res['code']; return $this->asJson($res); } $delivery = \app\models\DeliveryInfo::findOne(['order_no' => $order->order_no, 'store_id' => $order->store_id]); if($delivery['is_local'] == 1){ if($delivery['local_status'] > 0){ return $this->asJson([ 'code' => 1, 'msg' => '取消订单失败,原因:已经开始配送', 'data' => [ 'resultcode' => 0, ], ]); } return $this->asJson([ 'code' => 0, 'msg' => '取消订单', 'data' => [ 'resultcode' => 0, ], ]); } 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 $this->asJson($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() ]; } } /** * 线下转账信息(店铺) * * @return void */ public function actionPayOfflineSetting() { $store_id = get_store_id(); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => ['conf' => \app\modules\admin\models\SaasForm::offlineSetting($store_id)], 'store_id' => get_store_id(), ]); } /** * 点金计划订单详情 * @return \yii\web\Response */ public function actionGoldplan() { $form = new OrderDetailForm(); $orderNo = input_params('order_no', ''); return $this->asJson($form->goldplan($orderNo)); } public function actionTestAdapay() { include_once \Yii::$app->basePath . "/utils/Adapay/AdapaySdk/init.php"; \AdaPay\AdaPay::init([ "api_key_live" => "api_live_2fdb32b6-2807-4d4a-99f7-fc0a9b3c8fa5", "api_key_test" => "api_test_46be6a5e-c047-4cd0-9aac-c8c73a332f51", // "rsa_public_key" => "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCS0Fpi540Y5pPtItiRrsnguG8N22mwbNcHaA+ZfqDxEM32bNoLp7VhV/4T9jUS8plSYkH3kr7xmWl311f0qxEz5S4LbQACN/vDag48zsY2iTulhnCdpbhFqqCVnuK86g7uFyGhy9PJwGscXpmLxXkA1jwEFXM+8NTjfD8YsEdF0QIDAQAB", "rsa_private_key" => "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAJLQWmLnjRjmk+0i2JGuyeC4bw3babBs1wdoD5l+oPEQzfZs2guntWFX/hP2NRLymVJiQfeSvvGZaXfXV/SrETPlLgttAAI3+8NqDjzOxjaJO6WGcJ2luEWqoJWe4rzqDu4XIaHL08nAaxxemYvFeQDWPAQVcz7w1ON8PxiwR0XRAgMBAAECgYEAgg4gg80rqQtZr5BW2XdFTtUTS+s6zRcdxWnhp9ANMn/4dHwpDHocq4cPhQ9uJMLUH677UR2mGNAWJhuVxyBjs4J2qVFACpU4Ta9BRQXCppao3maB+04Uobik0xObAz6Fj+EitfO3HFrV6ilPtEMtiObd25uS/aQF7tLKgC+rs4ECQQDeTQyAtmWG+5Iacz1uIxLBWIyz5uIwdRb8pAcA/XIR/alv0IOEhPmYTq/6234av6CP9tWl65vOjozBY5D7RbDNAkEAqRHWNu0Zyw6koY6Pu3mivABanY0lZHigdSmxwAQqB8HnUXpuSscj5N1KxlTVvcPw40pbKOCrUoRXib9Cu3rZFQJAZdBkKY9gcLJH+FVPjWIC9QrZZowYjJkULiHyE0IBPLwxHkUh90/wARIJB5v/5cBeiZFDyPpgIfqn/OrdPDhvAQJAUd8JVN/MNcCJiJJ4l9h3LYMeXl0TVmvzh8kBAnMBx2/mjFY1QpDcmN9wbkp2lsZjyC0hp9HkJLlhiprLve3nYQJBAJZ8XdINDo+P9YJLEwMn1OrDG8h071YijgvAvHpZWxb+7GbUhExkDUVaT99jjLzGZ8mVvvTJ/VoqnFu4+ALyAjE=", ], "live", true); $app_id = 'app_9aa823b9-d959-4307-a931-23ba8780f9aa'; $open_id = 'oNiCd4gweWf2Irg2K5WfTFWFGEts'; # 初始化支付类 $payment = new \AdaPaySdk\Payment(); # 支付设置 $payment_params = array( "app_id"=> $app_id, "order_no"=> date("YmdHis").rand(100000, 999999), "pay_channel"=> "wx_lite", // "time_expire"=> "20200101000000", "pay_amt"=> "0.01", "goods_title"=> "subject", "goods_desc"=> "body", "description"=> "description", 'expend' => [ 'open_id' => $open_id, ], 'notify_url' => '', ); # 发起支付 $payment->create($payment_params); # 对支付结果进行处理 if ($payment->isError()){ //失败处理 var_dump($payment->result); } else { //成功处理 var_dump($payment->result); } } public function actionGetLocation() { $form = new OrderDetailForm(); $form->attributes = \Yii::$app->request->get(); $form->attributes = \Yii::$app->request->post(); $form->store_id = get_store_id(); return $this->asJson($form->map()); } //单品选择数量退款功能 public function actionOrderGoodsCancel() { $form = new OrderRevokeForm(); $form->attributes = post_params(); $form->user_id = get_user_id(); $form->store_id = get_store_id(); return $this->asJson($form->orderGoodsCancel()); } //单个待评论列表 public function actionOrderCommentWaitOnce() { $form = new OrderCommentForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->orderCommentOnce()); } //评论列表 public function actionOrderCommentWaitList() { $form = new OrderCommentForm(); $form->attributes = get_params(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); return $this->asJson($form->orderCommentWaitList()); } //已评价列表 public function actionOrderCommentList() { $form = new OrderCommentForm(); $form->attributes = get_params(); $form->user_id = get_user_id(); return $this->asJson($form->orderCommentList()); } }