| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\controllers\v1\pt;
- use AopClient;
- use app\models\Option;
- use app\models\Order;
- use app\models\OrderRefund;
- use app\models\StoreAliMini;
- use app\modules\client\behaviors\Auth;
- use app\modules\client\models\v1\OrderRefundForm;
- use app\modules\client\controllers\BaseController;
- use app\modules\client\models\v1\ExpressDetailForm;
- use app\modules\client\models\v1\pt\order\OrderPayDataForm;
- use app\modules\client\models\v1\pt\order\OrderSubmitForm;
- use app\modules\client\models\v1\pt\order\OrderSubmitPreviewForm;
- use app\modules\client\models\v1\OrderCommentForm;
- use app\modules\client\models\v1\OrderCommentPreview;
- use app\modules\client\models\v1\OrderConfirmForm;
- use app\modules\client\models\v1\OrderDetailForm;
- use app\modules\client\models\v1\OrderListForm;
- use app\modules\client\models\v1\OrderRefundDetailForm;
- use app\modules\client\models\v1\OrderRefundPreviewForm;
- use app\modules\client\models\v1\OrderRefundSendForm;
- use app\modules\client\models\v1\OrderRevokeForm;
- use app\modules\client\models\v1\pt\PtActivityOrderForm;
- use app\modules\client\models\v1\SaasOrderForm;
- use app\utils\Alipay\alipaySdk\aop\request\AlipayOpenAppQrcodeCreateRequest;
- use app\utils\Delivery\Delivery;
- use app\utils\Delivery\Alipay\ADelivery;
- use app\utils\ShareQrcode;
- use yii\base\BaseObject;
- include_once \Yii::$app->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()
- ];
- }
- }
- }
|