Ver código fonte

一些功能

Kirin 3 anos atrás
pai
commit
60f3541d06

+ 89 - 0
app/admin/controller/merchant/SystemStore.php

@@ -5,11 +5,17 @@ namespace app\admin\controller\merchant;
 use app\admin\controller\AuthController;
 use app\admin\model\order\StoreOrder as StoreOrderModel;
 use app\admin\model\order\StoreOrderStatus;
+use app\admin\model\store\StoreProductAttr;
+use app\admin\model\store\StoreProductAttrValue;
+use app\admin\model\system\ShippingTemplates;
 use app\admin\model\system\SystemStoreBill;
 use app\admin\model\system\SystemStoreExtract;
 use app\admin\model\system\SystemStorePoint;
+use app\admin\model\system\SystemStoreProductStock;
 use app\admin\model\ump\StorePink;
 use app\admin\model\user\User;
+use app\models\store\StoreCart;
+use app\models\store\StoreOrder;
 use crmeb\repositories\OrderRepository;
 use crmeb\services\FormBuilder;
 use crmeb\services\JsonService;
@@ -115,7 +121,67 @@ class SystemStore extends AuthController
         if (!$this->store_id) {
             $this->failed('未知门店');
         }
+//        $store_info = SystemStoreModel::get($this->store_id);
+        $stocks = SystemStoreProductStock::getStockList(['excel' => 0, 'page' => 1, 'limit' => PHP_INT_MAX], $this->store_id)['data'];
+        if ($stocks) $stocks = $stocks->toArray();
+//        dump($stocks);
+        $products = function () use ($stocks) {
+            $return = [];
+            foreach ($stocks as $v) {
+                $return[] = ['label' => $v['product_info']['store_name'] . "|" . $v['product_info']['product_attr_info']['suk'] . "【库存:{$v['stock']}】", 'value' => $v['unique']];
+            }
+            return $return;
+        };
+        $f = array();
+        $f[] = FormBuilder::select('uni', '商品')->setOptions($products())->filterable(true)->required();
+        $f[] = FormBuilder::number('num', '数量')->step(1)->min(0)->required();
+        $f[] = FormBuilder::input('real_name', '购买人')->required();
+        $f[] = FormBuilder::input('phone', '手机号码')->required();
+        $form = FormBuilder::make_post_form('创建订单', $f, Route::buildUrl('order_save'));
+        $this->assign(compact('form'));
+        return $this->fetch('public/form-builder');
+    }
+
 
+    public function order_save()
+    {
+        if (!$this->store_id) {
+            JsonService::fail('未知门店');
+        }
+        $date = UtilService::postMore([
+            ['uni', ''],
+            ['num', 0],
+            ['real_name', ''],
+            ['phone', ''],
+        ], $this->request);
+        if (!$date['uni']) JsonService::fail('请选择规格');
+        if (!$date['num']) JsonService::fail('请输入购买数量');
+        $uid = User::where('admin_id', $this->adminId)->value('uid');
+        if (!$uid) JsonService::fail('请先绑定前台账户');
+        $product = StoreProductAttrValue::where('unique', $date['uni'])->find();
+        if (!$product) JsonService::fail('规格不存在');
+        $res = StoreCart::setCart($uid, $product['product_id'], $date['num'], $date['uni'], 'product', 1);
+        if ($res) {
+            $cartId = $res->id;
+            $cartGroup = StoreCart::getUserProductCartList($uid, [$cartId], 1);
+            if (count($cartGroup['invalid'])) JsonService::fail($cartGroup['invalid'][0]['productInfo']['store_name'] . '已失效!');
+            if (!$cartGroup['valid']) JsonService::fail('请提交购买的商品');
+            $cartInfo = $cartGroup['valid'];
+            $priceGroup = StoreOrder::getOrderPriceGroup($cartInfo, 0);
+            $other = [
+                'offlinePostage' => sys_config('offline_postage'),
+                'integralRatio' => sys_config('integral_ratio')
+            ];
+            $orderKey = StoreOrder::cacheOrderInfo($uid, $cartInfo, $priceGroup, $other);
+            if (!$orderKey) JsonService::fail('生成订单错误!');
+            if (StoreOrder::be(['order_id|unique' => $orderKey, 'uid' => $uid, 'is_del' => 0]))
+                JsonService::fail('订单已生成');
+            $order = StoreOrder::cacheKeyCreateOrder($uid, $orderKey, 0, 'offline', false, 0, '加盟店后台订单', 0, 0, 0, 0, 0, false, 1, 2, $date['real_name'], $date['phone'], $this->store_id, 0, 1);
+            if ($order === false) JsonService::fail(StoreOrder::getErrorInfo('订单生成失败'));
+            else JsonService::success('订单已生成');
+        } else {
+            JsonService::fail('加入购物车失败');
+        }
     }
 
     /**
@@ -443,5 +509,28 @@ class SystemStore extends AuthController
         }
     }
 
+    /**
+     * 立即支付
+     * @param $id
+     */
+    public function offline($id)
+    {
+        if (!$this->store_id) {
+            JsonService::fail('未知门店');
+        }
+        $order = StoreOrder::get($id);
+        if ($order['store_id'] != $this->store_id) {
+            JsonService::fail('订单门店异常');
+        }
+        $res = StoreOrderModel::updateOffline($id);
+        if ($res) {
+            event('StoreProductOrderOffline', [$id]);
+            StoreOrderStatus::setStatus($id, 'offline', '线下付款');
+            return JsonService::successful('修改成功!');
+        } else {
+            return JsonService::fail(StoreOrderModel::getErrorInfo('修改失败!'));
+        }
+    }
+
     //TODO 库存管理
 }

+ 1 - 0
app/admin/model/order/StoreOrder.php

@@ -225,6 +225,7 @@ HTML;
             } else if ($item['paid'] == 1 && $item['refund_status'] == 2) {
                 $item['_status'] = 7;
             }
+            $item['_store_order'] = $item['store_order'] ? "后台下单" : "前台下单";
         }
         if (isset($where['excel']) && $where['excel'] == 1) {
             self::SaveExcel($data);

+ 14 - 2
app/admin/view/merchant/system_store/order.php

@@ -147,12 +147,17 @@
                     <div class="layui-btn-container" id="container-action">
                         <button class="layui-btn layui-btn-sm" data-type="del_order">批量删除订单</button>
                         <button class="layui-btn layui-btn-sm layui-btn-warm" data-type="write_order">订单核销</button>
+                        <button class="layui-btn layui-btn-sm layui-btn-warm" data-type="add_order">创建订单</button>
                     </div>
                     <table class="layui-hide" id="List" lay-filter="List"></table>
                     <!--订单-->
                     <script type="text/html" id="order_id">
                         {{d.order_id}}<br/>
                         <span style="color: {{d.color}};">{{d.pink_name}}</span><br/> 
+                        {{#  if(d.store_order == 1){ }}<span
+                                style="color: #8b0000;">[{{d._store_order}}]</span>{{# } }} 
+                        {{#  if(d.store_order == 0){ }}<span
+                                style="color: #18b566;">[{{d._store_order}}]</span>{{# } }} 
                         {{#  if(d.is_del == 1){ }}<span style="color: {{d.color}};">用户已删除</span>{{# } }} 
                     </script>
                     <!--用户信息-->
@@ -601,7 +606,7 @@
     layList.tool(function (event, data, obj) {
         switch (event) {
             case 'order_paid':
-                var url = layList.U({c: 'order.store_order', a: 'offline', p: {id: data.id}});
+                var url = layList.U({a: 'offline', p: {id: data.id}});
                 $eb.$swal('delete', function () {
                     $eb.axios.get(url).then(function (res) {
                         if (res.status == 200 && res.data.code == 200) {
@@ -663,7 +668,11 @@
                 }, {'title': '您确定要修改收货状态吗?', 'text': '修改后将无法恢复,请谨慎操作!', 'confirm': '是的,我要修改'})
                 break;
             case 'order_info':
-                $eb.createModalFrame(data.nickname + '订单详情', layList.U({c: 'order.store_order',a: 'order_info', q: {oid: data.id}}));
+                $eb.createModalFrame(data.nickname + '订单详情', layList.U({
+                    c: 'order.store_order',
+                    a: 'order_info',
+                    q: {oid: data.id}
+                }));
                 break;
             case 'order_print':
                 var url = layList.U({c: 'order.store_order', a: 'order_print', p: {id: data.id}});
@@ -702,6 +711,9 @@
         write_order: function () {
             return $eb.createModalFrame('订单核销', layList.U({a: 'write_order'}), {w: 500, h: 400});
         },
+        add_order: function () {
+            return $eb.createModalFrame('创建订单', layList.U({a: 'add_order'}), {w: 500, h: 400});
+        },
     };
     $('#container-action').find('button').each(function () {
         $(this).on('click', function () {

+ 2 - 0
app/admin/view/order/store_order/index.php

@@ -153,6 +153,8 @@
                     <script type="text/html" id="order_id">
                         {{d.order_id}}<br/>
                         <span style="color: {{d.color}};">{{d.pink_name}}</span><br/> 
+                        {{#  if(d.store_order == 1){ }}<span style="color: #8b0000;">[{{d._store_order}}]</span>{{# } }} 
+                        {{#  if(d.store_order == 0){ }}<span style="color: #18b566;">[{{d._store_order}}]</span>{{# } }} 
                         {{#  if(d.is_del == 1){ }}<span style="color: {{d.color}};">用户已删除</span>{{# } }} 
                     </script>
                     <!--用户信息-->

+ 11 - 8
app/models/store/StoreOrder.php

@@ -277,13 +277,13 @@ class StoreOrder extends BaseModel
      * @throws \think\exception\DbException
      */
 
-    public static function cacheKeyCreateOrder($uid, $key, $addressId, $payType, $useIntegral = false, $couponId = 0, $mark = '', $combinationId = 0, $pinkId = 0, $seckill_id = 0, $bargain_id = 0, $integral_id = 0, $test = false, $isChannel = 0, $shipping_type = 1, $real_name = '', $phone = '', $storeId = 0, $pointId = 0)
+    public static function cacheKeyCreateOrder($uid, $key, $addressId, $payType, $useIntegral = false, $couponId = 0, $mark = '', $combinationId = 0, $pinkId = 0, $seckill_id = 0, $bargain_id = 0, $integral_id = 0, $test = false, $isChannel = 0, $shipping_type = 1, $real_name = '', $phone = '', $storeId = 0, $pointId = 0, $store_order = 0)
     {
         self::beginTrans();
         try {
             $shipping_type = (int)$shipping_type;
             $offlinePayStatus = (int)sys_config('offline_pay_status') ?? (int)2;
-            if ($offlinePayStatus == 2) unset(self::$payType['offline']);
+            if ($offlinePayStatus == 2 && !$store_order) unset(self::$payType['offline']);
             if (!array_key_exists($payType, self::$payType)) return self::setErrorInfo('选择支付方式有误!', true);
             if (self::be(['unique' => $key, 'uid' => $uid])) return self::setErrorInfo('请勿重复提交订单', true);
             $userInfo = User::getUserInfo($uid);
@@ -376,7 +376,7 @@ class StoreOrder extends BaseModel
                 //门店自提没有邮费支付
                 $priceGroup['storePostage'] = 0;
                 $payPostage = 0;
-                if (!$pointId && !$test) {
+                if (!$pointId && !$test && !$store_order) {
                     return self::setErrorInfo('请选择自提点', true);
                 }
             }
@@ -464,17 +464,17 @@ class StoreOrder extends BaseModel
                 'deposit' => $deposit,
                 'deposit_back' => 0,
                 'deposit_status' => 0,
+                'store_order' => $store_order,
             ];
             $orderInfo['store_id'] = SystemStore::getStoreDispose($storeId, 'id');
             if (!$orderInfo['store_id']) return self::setErrorInfo('暂无门店无法选择门店!', true);
             if ($shipping_type === 2) {
                 $orderInfo['verify_code'] = self::getStoreCode();
-                $orderInfo['point_id'] = SystemStorePoint::verificWhere()->where('store_id', $orderInfo['store_id'])->where('id', $pointId)->value('id');
-                if (!$orderInfo['point_id']) return self::setErrorInfo('找不到对应自提点!', true);
+                if (!$store_order) {
+                    $orderInfo['point_id'] = SystemStorePoint::verificWhere()->where('store_id', $orderInfo['store_id'])->where('id', $pointId)->value('id');
+                    if (!$orderInfo['point_id']) return self::setErrorInfo('找不到对应自提点!', true);
+                }
             }
-            //门店库存
-            $res4 = SystemStore::decStock($orderInfo);
-            if (!$res4) return self::setErrorInfo(SystemStore::getErrorInfo(), true);
 
             $order = self::create($orderInfo);
             if (!$order) return self::setErrorInfo('订单生成失败!', true);
@@ -489,6 +489,9 @@ class StoreOrder extends BaseModel
             }
 //保存购物车商品信息
             $res4 = false !== StoreOrderCartInfo::setCartInfo($order['id'], $cartInfo);
+            //门店库存
+            $res4 = $res4 && SystemStore::decStock($order);
+            if (!$res4) return self::setErrorInfo(SystemStore::getErrorInfo(), true);
 //购物车状态修改
             $res6 = false !== StoreCart::where('id', 'IN', $cartIds)->update(['is_pay' => 1]);
             if (!$res4 || !$res5 || !$res6) return self::setErrorInfo('订单生成失败!', true);

+ 8 - 2
app/models/system/SystemStore.php

@@ -218,16 +218,22 @@ class SystemStore extends BaseModel
     {
         $res = true;
         if (!$orderInfo['store_id']) return $res;
+//        var_dump($orderInfo);
         $cartId = is_string($orderInfo['cart_id']) ? json_decode($orderInfo['cart_id'], true) : $orderInfo['cart_id'];
         $cartInfo = StoreOrderCartInfo::whereIn('cart_id', $cartId)->column('cart_info');
+//        dump($cartId);
+//        exit;
         $userInfo = User::getUserInfo($orderInfo['uid']);
         foreach ($cartInfo as $value) {
             $product = json_decode($value, true);
+//            var_dump($product);
+//            exit;
             $cartNum = $product['cart_num'] ?? 0;
             if (isset($product['productInfo'])) {
-                $res = SystemStoreProductStockLog::expend($orderInfo['store_id'], $product['product_id'], $product['product_attr_unique'], 'sale', $orderInfo['id'], $cartNum, 0, '用户' . $userInfo['nickname'] . '购买订单完成');
+                $res = $res && SystemStoreProductStockLog::expend($orderInfo['store_id'], $product['product_id'], $product['product_attr_unique'], 'sale', $orderInfo['id'], $cartNum, 0, '用户' . $userInfo['nickname'] . '购买订单完成');
             }
         }
-        return $res ? $res : self::setErrorInfo(SystemStoreProductStockLog::getErrorInfo());
+//        var_dump($res);
+        return $res ?: self::setErrorInfo(SystemStoreProductStockLog::getErrorInfo());
     }
 }