瀏覽代碼

修改订单接口

Anyon 4 年之前
父節點
當前提交
575e4519b4
共有 2 個文件被更改,包括 25 次插入27 次删除
  1. 4 4
      app/data/controller/api/Notify.php
  2. 21 23
      app/data/controller/api/auth/Order.php

+ 4 - 4
app/data/controller/api/Notify.php

@@ -26,7 +26,7 @@ class Notify extends Controller
         $notify = ($payment = WechatService::WePayOrder())->getNotify();
         if ($notify['result_code'] == 'SUCCESS' && $notify['return_code'] == 'SUCCESS') {
             if ($scene === 'order') {
-                if ($this->setOrder($notify['out_trade_no'], $notify['transaction_id'], $notify['cash_fee'] / 100, 'wxpay')) {
+                if ($this->setOrder($notify['out_trade_no'], $notify['cash_fee'] / 100, $notify['transaction_id'], 'wxpay')) {
                     return $payment->getNotifySuccessReply();
                 }
             }
@@ -38,15 +38,15 @@ class Notify extends Controller
     /**
      * 订单状态更新
      * @param string $code 订单单号
-     * @param string $payno 交易单号
      * @param string $amount 交易金额
+     * @param string $paycode 交易单号
      * @param string $paytype 支付类型
      * @return boolean
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    private function setOrder($code, $payno, $amount, $paytype = 'wxpay')
+    private function setOrder($code, $amount, $paycode, $paytype = 'wxpay')
     {
         // 检查订单支付状态
         $map = ['order_no' => $code, 'payment_status' => 0, 'status' => 2];
@@ -55,8 +55,8 @@ class Notify extends Controller
         // 更新订单支付状态
         $this->app->db->name('StoreOrder')->where($map)->update([
             'status'           => 3,
-            'payment_no'       => $payno,
             'payment_type'     => $paytype,
+            'payment_code'     => $paycode,
             'payment_status'   => 1,
             'payment_amount'   => $amount,
             'payment_remark'   => '微信在线支付',

+ 21 - 23
app/data/controller/api/auth/Order.php

@@ -199,25 +199,23 @@ class Order extends Auth
     public function get()
     {
         $map = [['mid', '=', $this->mid]];
-        if ($this->request->has('order_no', 'post', true)) {
-            $map[] = ['order_no', '=', $this->request->post('order_no')];
-        } else {
-            $map[] = ['status', 'in', ['0', '2', '3', '4', '5']];
-        }
-        if ($this->request->has('status', 'post', true)) {
-            $map[] = ['status', '=', $this->request->post('status')];
+        if (!$this->request->has('order_no', 'param', true)) {
+            $map[] = ['status', 'in', [0, 2, 3, 4, 5]];
         }
-        $result = $this->_query('ShopOrder')->where($map)->order('id desc')->page(true, false, false, 20);
-        $codes = array_unique(array_column($result['list'], 'order_no'));
-        $glist = $this->app->db->name('ShopOrderList')->whereIn('order_no', $codes)->select()->toArray();
-        foreach ($result['list'] as &$vo) {
-            [$vo['goods_count'], $vo['list']] = [0, []];
-            foreach ($glist as $goods) if ($vo['order_no'] === $goods['order_no']) {
-                $vo['list'][] = $goods;
-                $vo['goods_count'] += $goods['number_goods'];
+        $query = $this->_query('ShopOrder')->equal('status,order_no');
+        $result = $query->where($map)->order('id desc')->page(true, false, false, 20);
+        if (count($result['list']) > 0) {
+            $codes = array_unique(array_column($result['list'], 'order_no'));
+            $items = $this->app->db->name('ShopOrderItem')->whereIn('order_no', $codes)->select()->toArray();
+            foreach ($result['list'] as &$vo) {
+                [$vo['count'], $vo['items']] = [0, []];
+                foreach ($items as $item) if ($vo['order_no'] === $item['order_no']) {
+                    $vo['items'][] = $item;
+                    $vo['count'] += $item['stock_sales'];
+                }
             }
         }
-        $this->success('获取订单列表成功!', $result);
+        $this->success('获取订单数据成功!', $result);
     }
 
     /**
@@ -228,15 +226,15 @@ class Order extends Auth
      */
     public function cancel()
     {
-        $map = $this->_vali(['mid' => $this->mid, 'order_no.require' => '订单号不能为空!']);
-        $order = $this->app->db->name('ShopOrder')->where($map)->find();
+        $map = $this->_vali(['order_no.require' => '订单号不能为空!']);
+        $order = $this->app->db->name('ShopOrder')->where(['mid' => $this->mid])->where($map)->find();
         if (empty($order)) $this->error('订单查询失败,请稍候再试!');
         if (in_array($order['status'], [1, 2])) {
             $result = $this->app->db->name('ShopOrder')->where($map)->update([
-                'status'        => 0,
-                'cancel_state'  => 1,
-                'cancel_stime'  => date('Y-m-d H:i:s'),
-                'cancel_remark' => '用户主动取消订单!',
+                'status'          => 0,
+                'cancel_status'   => 1,
+                'cancel_remark'   => '用户主动取消订单!',
+                'cancel_datetime' => date('Y-m-d H:i:s'),
             ]);
             if ($result !== false && OrderService::instance()->syncStock($order['order_no'])) {
                 $this->success('订单取消成功!');
@@ -338,7 +336,7 @@ class Order extends Auth
         $map = $this->_vali(['order_no.require' => '订单编号不能为空!']);
         $order = $this->app->db->name('ShopOrder')->where(['mid' => $this->mid])->where($map)->find();
         if (empty($order)) $this->error('订单查询失败!');
-        $order['list'] = $this->app->db->name('ShopOrderList')->where($map)->select()->toArray();
+        $order['list'] = $this->app->db->name('ShopOrderItem')->where($map)->select()->toArray();
         $rlist = $this->app->db->name('ShopOrderRefund')->where($map)->whereIn('refund_status', [1, 2, 3])->select()->toArray();
         if (count($order['list']) > 0) foreach ($order['list'] as &$vo) if (count($rlist) > 0) foreach ($rlist as $rule) {
             if ($vo['goods_id'] === $rule['goods_id'] && $vo['goods_spec'] === $rule['goods_spec']) {