wufeng 2 سال پیش
والد
کامیت
fc133a546d

+ 0 - 25
app/mobile/controller/Exchange.php

@@ -29,29 +29,4 @@ class Exchange extends BaseController
         return ExchangeLogic::goodInfo($code);
     }
 
-    //兑换商品下单
-    public function orderAdd(){
-
-        $param = $this->request->only(['good_id','addr_id','num','remark'],'post');
-
-        $val = Validate::rule(Config::get('validate_rules.ExchangeOrderAdd'));
-
-        if(!$val->check($param)) throw new ValidateException($val->getError());
-
-        return ExchangeLogic::orderAdd($param);
-
-    }
-
-    //兑换订单列表
-    public function orderList(){
-        $param = $this->request->only(['page' => 1, 'size' => 10,'status'=>''], 'post');
-        return ExchangeLogic::orderList($param);
-    }
-
-    //兑换订单详情
-    public function orderInfo(){
-        $id = $this->request->post('id/d', 0);
-        return ExchangeLogic::orderInfo($id);
-    }
-
 }

+ 40 - 0
app/mobile/controller/Order.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace app\mobile\controller;
+
+use app\BaseController;
+use app\mobile\logic\OrderLogic;
+use think\exception\ValidateException;
+use think\facade\Config;
+use think\facade\Validate;
+
+//【订单】
+class Order extends BaseController
+{
+    //兑换商品下单
+    public function add(){
+
+        $param = $this->request->only(['good_id','addr_id','num','remark'],'post');
+
+        $val = Validate::rule(Config::get('validate_rules.ExchangeOrderAdd'));
+
+        if(!$val->check($param)) throw new ValidateException($val->getError());
+
+        return OrderLogic::add($param);
+
+    }
+
+    //订单列表
+    public function list(){
+        $param = $this->request->only(['page' => 1, 'size' => 10,'status'=>''], 'post');
+        return OrderLogic::list($param);
+    }
+
+    //订单详情
+    public function info(){
+        $id = $this->request->post('id/d', 0);
+        return OrderLogic::info($id);
+    }
+
+
+}

+ 7 - 0
app/mobile/logic/CommonLogic.php

@@ -3,6 +3,7 @@
 namespace app\mobile\logic;
 
 use app\model\AccountModel;
+use app\model\AddrModel;
 use app\model\CommonModel;
 use app\model\GoodModel;
 use app\model\GroupModel;
@@ -83,6 +84,12 @@ class CommonLogic extends BaseLogic
 
         try {
 
+            $rs = AddrModel::field('id')
+                ->where(['is_del' => CommonModel::$del_normal, 'id' => $data['addr_id'], 'uid' => self::$aid])
+                ->findOrEmpty()
+                ->isEmpty();
+            if ($rs) throw new Exception('该地址不存在');
+
             $amount = '0';//支付金额
             $num = array_column($data['list'], 'num', 'id');//
             $date = date('Y-m-d H:i:s');

+ 0 - 124
app/mobile/logic/ExchangeLogic.php

@@ -61,130 +61,6 @@ class ExchangeLogic extends BaseLogic
 
     }
 
-    //兑换商品下单
-    public static function orderAdd(array $data = []): Json
-    {
-        Db::startTrans();
-
-        try {
-
-            //判断收货地址
-
-            $rs = AddrModel::field('id')
-                ->where(['is_del' => CommonModel::$del_normal, 'id' => $data['addr_id'], 'uid' => self::$aid])
-                ->findOrEmpty()
-                ->isEmpty();
-            if ($rs) throw new Exception('该地址不存在');
-
-
-            //判断商品
-            $rs = CompanyGoodModel::alias('a')
-                ->field('a.id,a.good_id,b.good_code,b.good_name,b.status,b.moq,c.id inventory_id,c.inventory')
-                ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
-                ->leftJoin('inventory_exchange c', 'c.account_id=' . self::$aid . ' AND c.good_id=a.good_id')
-                ->where(['a.is_del' => CommonModel::$del_normal, 'a.group_id' => self::$group_id, 'a.good_id' => $data['good_id']])
-                ->findOrEmpty();
-
-            if ($rs->isEmpty()) throw new Exception('该商品不存在或不允许兑换');
-            if ($rs->status != CommonModel::$status_normal) throw new Exception('该商品已被禁用');
-            if ($rs->moq > $data['num']) throw new Exception('不满足该商品的起订量,' . $rs->moq);
-            if ($rs->inventory < $data['num']) throw new Exception('库存数不足');
-
-            $date = date('Y-m-d H:i:s');
-
-            $after_inventory = bcsub($rs->inventory, $data['num']);
-
-            //添加库存变动记录
-            Db::name('inventory_exchange_log')
-                ->insert([
-                    'inventory_exchange_id' => $rs->inventory_id,
-                    'before_inventory' => $rs->inventory,
-                    'after_inventory' => $after_inventory,
-                    'good_id' => $rs->good_id,
-                    'good_code' => $rs->good_code,
-                    'good_name' => $rs->good_name,
-                    'source' => CommonModel::$source_account,
-                    'createrid' => self::$aid,
-                    'creater' => self::$aname,
-                    'addtime' => $date
-                ]);
-
-            //扣减库存
-            InventoryExchangeModel::where('id', $rs->inventory_id)
-                ->save(['inventory' => $after_inventory, 'updaterid' => self::$aid, 'updater' => self::$aname, 'updatetime' => $date]);
-
-            //生成兑换订单
-            OrderModel::create([
-                'orderCode' => make_no('QR'),
-                'company_id' => self::$company_id,
-                'card_id' => self::$card_id,
-                'uid' => self::$aid,
-                'good_id' => $rs->good_id,
-                'num' => $data['num'],
-                'price'=>0,
-                'total_price'=>0,
-                'addr_id' => $data['addr_id'],
-                'type' => GoodModel::$type_exchange,
-                'remark' => $data['remark'],
-                'status' => CommonModel::$order_status_not_deliver,
-                'is_del' => CommonModel::$del_normal,
-                'creater' => self::$aname,
-                'createrid' => self::$aid,
-                'addtime' => $date,
-                'updater' => self::$aname,
-                'updaterid' => self::$aid,
-                'updatetime' => $date,
-            ])->save();
-
-            Db::commit();
-
-            return json_show(CommonModel::$success, '兑换商品成功');
-        } catch (Exception $exception) {
-            Db::rollback();
-            return json_show(CommonModel::$error_param, '兑换失败,' . $exception->getMessage());
-        }
-
-    }
-
-    //兑换订单列表
-    public static function orderList(array $data = []): Json
-    {
-        $db = OrderModel::alias('a')
-            ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
-            ->where('a.is_del', CommonModel::$del_normal);
-
-        if ($data['status'] != '') $db->where('a.status', $data['status']);
-
-        $count = $db->count('a.id');
-
-        $list = $db
-            ->field('a.id,a.orderCode,b.good_name,a.num,a.status,a.addtime')
-            ->page($data['page'], $data['size'])
-            ->order('a.id', 'desc')
-            ->select()
-            ->toArray();
-
-        return json_show(CommonModel::$success, '获取兑换订单列表成功', ['count' => $count, 'list' => $list]);
-
-    }
-
-    //兑换订单详情
-    public static function orderInfo(int $id = 0): Json
-    {
-        $rs = OrderModel::alias('a')
-            ->field('a.id,a.orderCode,a.status,a.addtime,b.good_name,a.num,c.contactor,c.mobile,c.addr,c.addr_code')
-            ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
-            ->leftJoin('addr c', 'c.id=a.addr_id AND c.is_del=' . CommonModel::$del_normal)
-            ->where(['a.is_del' => CommonModel::$del_normal, 'a.id' => $id])
-            ->withAttr('addr', function ($val, $da) {
-                return $da['addr_code'] ? get_addr_name($da['addr_code']) . $val : $val;
-            })
-            ->findOrEmpty()
-            ->toArray();
-
-        return $rs ? json_show(CommonModel::$success, '获取兑换订单详情成功', $rs) : json_show(CommonModel::$error_param, '该订单不存在');
-
-    }
 
 
 }

+ 147 - 0
app/mobile/logic/OrderLogic.php

@@ -0,0 +1,147 @@
+<?php
+
+
+namespace app\mobile\logic;
+
+
+use app\model\AddrModel;
+use app\model\CommonModel;
+use app\model\CompanyGoodModel;
+use app\model\GoodModel;
+use app\model\InventoryExchangeModel;
+use app\model\OrderModel;
+use think\facade\Db;
+use think\response\Json;
+
+class OrderLogic extends BaseLogic
+{
+
+    //兑换商品下单
+    public static function add(array $data = []): Json
+    {
+        Db::startTrans();
+
+        try {
+
+            //判断收货地址
+
+            $rs = AddrModel::field('id')
+                ->where(['is_del' => CommonModel::$del_normal, 'id' => $data['addr_id'], 'uid' => self::$aid])
+                ->findOrEmpty()
+                ->isEmpty();
+            if ($rs) throw new Exception('该地址不存在');
+
+
+            //判断商品
+            $rs = CompanyGoodModel::alias('a')
+                ->field('a.id,a.good_id,b.good_code,b.good_name,b.status,b.moq,c.id inventory_id,c.inventory')
+                ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
+                ->leftJoin('inventory_exchange c', 'c.account_id=' . self::$aid . ' AND c.good_id=a.good_id')
+                ->where(['a.is_del' => CommonModel::$del_normal, 'a.group_id' => self::$group_id, 'a.good_id' => $data['good_id']])
+                ->findOrEmpty();
+
+            if ($rs->isEmpty()) throw new Exception('该商品不存在或不允许兑换');
+            if ($rs->status != CommonModel::$status_normal) throw new Exception('该商品已被禁用');
+            if ($rs->moq > $data['num']) throw new Exception('不满足该商品的起订量,' . $rs->moq);
+            if ($rs->inventory < $data['num']) throw new Exception('库存数不足');
+
+            $date = date('Y-m-d H:i:s');
+
+            $after_inventory = bcsub($rs->inventory, $data['num']);
+
+            //添加库存变动记录
+            Db::name('inventory_exchange_log')
+                ->insert([
+                    'inventory_exchange_id' => $rs->inventory_id,
+                    'before_inventory' => $rs->inventory,
+                    'after_inventory' => $after_inventory,
+                    'flag' => '-1',
+                    'good_id' => $rs->good_id,
+                    'good_code' => $rs->good_code,
+                    'good_name' => $rs->good_name,
+                    'source' => CommonModel::$source_account,
+                    'createrid' => self::$aid,
+                    'creater' => self::$aname,
+                    'addtime' => $date
+                ]);
+
+            //扣减库存
+            InventoryExchangeModel::where('id', $rs->inventory_id)
+                ->save(['inventory' => $after_inventory, 'updaterid' => self::$aid, 'updater' => self::$aname, 'updatetime' => $date]);
+
+            //生成兑换订单
+            OrderModel::create([
+                'orderCode' => make_no('QR'),
+                'company_id' => self::$company_id,
+                'card_id' => self::$card_id,
+                'uid' => self::$aid,
+                'good_id' => $rs->good_id,
+                'num' => $data['num'],
+                'price' => 0,
+                'total_price' => 0,
+                'addr_id' => $data['addr_id'],
+                'type' => GoodModel::$type_exchange,
+                'remark' => $data['remark'],
+                'status' => CommonModel::$order_status_not_deliver,
+                'is_del' => CommonModel::$del_normal,
+                'creater' => self::$aname,
+                'createrid' => self::$aid,
+                'addtime' => $date,
+                'updater' => self::$aname,
+                'updaterid' => self::$aid,
+                'updatetime' => $date,
+            ])->save();
+
+            Db::commit();
+
+            return json_show(CommonModel::$success, '兑换商品成功');
+        } catch (Exception $exception) {
+            Db::rollback();
+            return json_show(CommonModel::$error_param, '兑换失败,' . $exception->getMessage());
+        }
+
+    }
+
+    //订单列表
+    public static function list(array $data = []): Json
+    {
+        $db = OrderModel::alias('a')
+            ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
+            ->where(['a.is_del'=>CommonModel::$del_normal, 'a.uid' => self::$aid]);
+
+        if ($data['status'] != '') $db->where('a.status', $data['status']);
+
+        $count = $db->count('a.id');
+
+        $list = $db
+            ->field('a.id,a.orderCode,b.good_name,a.num,a.status,a.addtime,a.type,a.price,a.total_price')
+            ->page($data['page'], $data['size'])
+            ->order('a.id', 'desc')
+            ->select()
+            ->toArray();
+
+        return json_show(CommonModel::$success, '获取订单列表成功', ['count' => $count, 'list' => $list]);
+
+    }
+
+    //订单详情
+    public static function info(int $id = 0): Json
+    {
+        $rs = OrderModel::alias('a')
+            ->field('a.id,a.orderCode,a.status,a.addtime,a.type,b.good_name,a.num,c.contactor,c.mobile,c.addr,c.addr_code,a.price,a.total_price,a.post_name,a.post_code,a.remark,"支付流水号" p')
+            ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
+            ->leftJoin('addr c', 'c.id=a.addr_id AND c.is_del=' . CommonModel::$del_normal)
+            ->leftJoin('pay_info d', 'd.id=a.pay_info_id')
+            ->where(['a.is_del' => CommonModel::$del_normal, 'a.id' => $id, 'a.uid' => self::$aid])
+            ->withAttr('addr', function ($val, $da) {
+                return $da['addr_code'] ? get_addr_name($da['addr_code']) . $val : $val;
+            })
+            ->findOrEmpty()
+            ->toArray();
+
+        return $rs ? json_show(CommonModel::$success, '获取订单详情成功', $rs) : json_show(CommonModel::$error_param, '该订单不存在');
+
+    }
+
+
+}

+ 12 - 11
app/mobile/route/app.php

@@ -22,20 +22,21 @@ Route::rule('addrRead', 'Addr/read');//读取
 Route::rule('addrEdit', 'Addr/edit');//修改
 Route::rule('addrDelete', 'Addr/delete');//删除
 
-//【服务】
-Route::rule('serviceList', 'Service/list');//列表
-Route::rule('serviceRead', 'Service/read');//读取
+//【服务和商品】
+Route::rule('serviceList', 'Service/list');//服务列表
+Route::rule('serviceRead', 'Service/read');//服务详情
+Route::rule('exchangeGoodList', 'Exchange/goodList');//兑换商品列表
+Route::rule('exchangeGoodInfo', 'Exchange/goodInfo');//兑换商品详情
+Route::rule('shoppingGoodList', 'Shopping/goodList');//商城商品列表
+Route::rule('shoppingGoodInfo', 'Shopping/goodInfo');//商城商品详情
 
-//【兑换商品】
-Route::rule('exchangeGoodList', 'Exchange/goodList');//商品列表
-Route::rule('exchangeGoodInfo', 'Exchange/goodInfo');//商品详情
-Route::rule('exchangeOrderAdd', 'Exchange/orderAdd');//兑换商品下单
-Route::rule('exchangeOrderList', 'Exchange/orderList');//兑换订单列表
-Route::rule('exchangeOrderInfo', 'Exchange/orderInfo');//兑换订单详情
+//【订单】
+Route::rule('orderAdd', 'Order/add');//兑换商品下单
+Route::rule('orderList', 'Order/list');//订单列表
+Route::rule('orderInfo', 'Order/info');//订单详情
 
 //【商城商品】
-Route::rule('shoppingGoodList', 'Shopping/goodList');//商城商品列表
-Route::rule('shoppingGoodInfo', 'Shopping/goodInfo');//商城商品详情
+