Browse Source

一些功能

Kirin 4 years ago
parent
commit
28178b146f

+ 5 - 3
app/admin/controller/system/SystemStore.php

@@ -235,10 +235,12 @@ class SystemStore extends AuthController
             $field = [];
             $field = [];
             $field[] = FormBuilder::frameImages('product', '选择商品', Route::buildUrl('productList', array('fodder' => 'product')))->icon('plus')->width('100%')->height('500px');
             $field[] = FormBuilder::frameImages('product', '选择商品', Route::buildUrl('productList', array('fodder' => 'product')))->icon('plus')->width('100%')->height('500px');
             $field[] = FormBuilder::hidden('product_id', '');
             $field[] = FormBuilder::hidden('product_id', '');
+            $field[] = FormBuilder::number('price', 0)->step(0.01);
             $field[] = FormBuilder::hidden('unique', '');
             $field[] = FormBuilder::hidden('unique', '');
         } else {
         } else {
             $field = [];
             $field = [];
             $field[] = FormBuilder::hidden('product_id', $where['product_id']);
             $field[] = FormBuilder::hidden('product_id', $where['product_id']);
+            $field[] = FormBuilder::number('price', SystemStoreProductStock::where(['product_id' => $where['product_id'], 'unique' => $where['unique'], 'store_id' => $id])->value('price'))->step(0.01);
             $field[] = FormBuilder::hidden('unique', $where['unique']);
             $field[] = FormBuilder::hidden('unique', $where['unique']);
         }
         }
         $field[] = FormBuilder::number('stock', '库存增加量', 0);
         $field[] = FormBuilder::number('stock', '库存增加量', 0);
@@ -265,7 +267,7 @@ class SystemStore extends AuthController
         if (!$id) {
         if (!$id) {
             Json::fail('请选择门店');
             Json::fail('请选择门店');
         }
         }
-        list($product_id, $unique, $stock) = UtilService::postMore([['product_id', []], ['unique', []], ['stock', 0]], $this->request, true);
+        list($product_id, $unique, $stock, $price) = UtilService::postMore([['product_id', []], ['unique', []], ['stock', 0], ['price', 0]], $this->request, true);
         if (!count($product_id)) {
         if (!count($product_id)) {
             Json::fail('请选择补货商品');
             Json::fail('请选择补货商品');
         }
         }
@@ -273,9 +275,9 @@ class SystemStore extends AuthController
         SystemStoreProductStockLog::beginTrans();
         SystemStoreProductStockLog::beginTrans();
         foreach ($product_id as $k => $v) {
         foreach ($product_id as $k => $v) {
             if ($stock > 0) {
             if ($stock > 0) {
-                $res = $res && SystemStoreProductStockLog::income($id, $v, $unique[$k], 'add_stock', 0, $stock, $this->adminId, '后台补货' . $stock . '件', 1);
+                $res = $res && SystemStoreProductStockLog::income($id, $v, $unique[$k], 'add_stock', 0, $stock, $this->adminId, '后台补货' . $stock . '件', 1, $price);
             } else {
             } else {
-                $res = $res && SystemStoreProductStockLog::expend($id, $v, $unique[$k], 'dec_stock', 0, abs($stock), $this->adminId, '后台减货' . $stock . '件', 1);
+                $res = $res && SystemStoreProductStockLog::expend($id, $v, $unique[$k], 'dec_stock', 0, abs($stock), $this->adminId, '后台减货' . $stock . '件', 1, $price);
             }
             }
         }
         }
         if ($res) {
         if ($res) {

+ 6 - 6
app/admin/model/system/SystemStoreProductStockLog.php

@@ -36,7 +36,7 @@ class SystemStoreProductStockLog extends BaseModel
 
 
 
 
     //修改库存减少库存记录
     //修改库存减少库存记录
-    public static function expend($store_id, $product_id, $unique, $type, $link_id, $number, $adder_id, $mark = '', $status = 1)
+    public static function expend($store_id, $product_id, $unique, $type, $link_id, $number, $adder_id, $mark = '', $status = 1, $price = 0)
     {
     {
         $info = StoreProductAttrValue::where(['unique' => $unique])->find();
         $info = StoreProductAttrValue::where(['unique' => $unique])->find();
         if (!$info) {
         if (!$info) {
@@ -50,7 +50,7 @@ class SystemStoreProductStockLog extends BaseModel
         }
         }
         $stock = SystemStoreProductStock::where(['product_id' => $product_id, 'unique' => $unique, 'store_id' => $store_id])->find();
         $stock = SystemStoreProductStock::where(['product_id' => $product_id, 'unique' => $unique, 'store_id' => $store_id])->find();
         if (!$stock) {
         if (!$stock) {
-            $stock = SystemStoreProductStock::create(['product_id' => $product_id, 'unique' => $unique, 'store_id' => $store_id, 'add_time' => time(), 'stock' => 0, 'in_use' => 0]);
+            $stock = SystemStoreProductStock::create(['product_id' => $product_id, 'unique' => $unique, 'store_id' => $store_id, 'add_time' => time(), 'stock' => 0, 'in_use' => 0, 'price' => $price]);
         }
         }
         if (!$stock['in_use']) return self::setErrorInfo('所选门店未上架' . StoreProduct::get($product_id)['store_name'] . '[' . $info['suk'] . ']');
         if (!$stock['in_use']) return self::setErrorInfo('所选门店未上架' . StoreProduct::get($product_id)['store_name'] . '[' . $info['suk'] . ']');
         if ($number > 0) {
         if ($number > 0) {
@@ -58,7 +58,7 @@ class SystemStoreProductStockLog extends BaseModel
             if ($balance < 0) {
             if ($balance < 0) {
                 return self::setErrorInfo('所选门店' . StoreProduct::get($product_id)['store_name'] . '[' . $info['suk'] . ']库存不足');
                 return self::setErrorInfo('所选门店' . StoreProduct::get($product_id)['store_name'] . '[' . $info['suk'] . ']库存不足');
             }
             }
-            SystemStoreProductStock::where('id', $stock['id'])->dec('stock', $number)->update();
+            SystemStoreProductStock::where('id', $stock['id'])->dec('stock', $number)->update(['price' => $price]);
             $pm = 0;
             $pm = 0;
             $add_time = time();
             $add_time = time();
             $stock_id = $stock['id'];
             $stock_id = $stock['id'];
@@ -69,7 +69,7 @@ class SystemStoreProductStockLog extends BaseModel
     }
     }
 
 
     //修改库存增加库存记录
     //修改库存增加库存记录
-    public static function income($store_id, $product_id, $unique, $type, $link_id, $number, $adder_id, $mark = '', $status = 1)
+    public static function income($store_id, $product_id, $unique, $type, $link_id, $number, $adder_id, $mark = '', $status = 1, $price = 0)
     {
     {
         $info = StoreProductAttrValue::where(['unique' => $unique])->find();
         $info = StoreProductAttrValue::where(['unique' => $unique])->find();
         if (!$info) {
         if (!$info) {
@@ -83,11 +83,11 @@ class SystemStoreProductStockLog extends BaseModel
         }
         }
         $stock = SystemStoreProductStock::where(['product_id' => $product_id, 'unique' => $unique, 'store_id' => $store_id])->find();
         $stock = SystemStoreProductStock::where(['product_id' => $product_id, 'unique' => $unique, 'store_id' => $store_id])->find();
         if (!$stock) {
         if (!$stock) {
-            $stock = SystemStoreProductStock::create(['product_id' => $product_id, 'unique' => $unique, 'store_id' => $store_id, 'add_time' => time(), 'stock' => 0, 'in_use' => 1]);
+            $stock = SystemStoreProductStock::create(['product_id' => $product_id, 'unique' => $unique, 'store_id' => $store_id, 'add_time' => time(), 'stock' => 0, 'in_use' => 1, 'price' => $price]);
         }
         }
         if ($number > 0) {
         if ($number > 0) {
             $balance = $stock['stock'] + $number;
             $balance = $stock['stock'] + $number;
-            SystemStoreProductStock::where('id', $stock['id'])->inc('stock', $number)->update(['in_use' => 1]);
+            SystemStoreProductStock::where('id', $stock['id'])->inc('stock', $number)->update(['in_use' => 1, 'price' => $price]);
             $pm = 1;
             $pm = 1;
             $add_time = time();
             $add_time = time();
             $stock_id = $stock['id'];
             $stock_id = $stock['id'];

+ 4 - 0
app/admin/view/system/system_store/product_list.php

@@ -91,6 +91,7 @@
             {field: 'image', title: '商品图片', templet: '#image', width: '12%'},
             {field: 'image', title: '商品图片', templet: '#image', width: '12%'},
             {field: 'store_name', title: '商品名称', templet: '#store_name', width: '30%'},
             {field: 'store_name', title: '商品名称', templet: '#store_name', width: '30%'},
             {field: 'suk', title: '规格', width: '20%'},
             {field: 'suk', title: '规格', width: '20%'},
+            {field: 'price', title: '价格', width: '20%'},
             {field: 'right', title: '操作', align: 'center', toolbar: '#act'}
             {field: 'right', title: '操作', align: 'center', toolbar: '#act'}
         ]
         ]
     });
     });
@@ -101,6 +102,7 @@
                 parent.$f.changeField('product', [data.image]);
                 parent.$f.changeField('product', [data.image]);
                 parent.$f.changeField('product_id', [data.product_id]);
                 parent.$f.changeField('product_id', [data.product_id]);
                 parent.$f.changeField('unique', [data.unique]);
                 parent.$f.changeField('unique', [data.unique]);
+                parent.$f.changeField('price', [data.price]);
                 parent.$f.closeModal(parentinputname);
                 parent.$f.closeModal(parentinputname);
                 break;
                 break;
         }
         }
@@ -114,6 +116,7 @@
             var uniques = layList.getCheckData().getIds('unique');
             var uniques = layList.getCheckData().getIds('unique');
             var product_ids = layList.getCheckData().getIds('product_id');
             var product_ids = layList.getCheckData().getIds('product_id');
             var product = layList.getCheckData().getIds('image');
             var product = layList.getCheckData().getIds('image');
+            var price = layList.getCheckData().getIds('price');
             if (uniques.length) {
             if (uniques.length) {
                 // console.log(uniques)
                 // console.log(uniques)
                 // console.log(product_ids)
                 // console.log(product_ids)
@@ -121,6 +124,7 @@
                 parent.$f.changeField('product', product);
                 parent.$f.changeField('product', product);
                 parent.$f.changeField('product_id', product_ids);
                 parent.$f.changeField('product_id', product_ids);
                 parent.$f.changeField('unique', uniques);
                 parent.$f.changeField('unique', uniques);
+                parent.$f.changeField('price', price);
                 parent.$f.closeModal(parentinputname);
                 parent.$f.closeModal(parentinputname);
             } else {
             } else {
                 layList.msg('请选择商品');
                 layList.msg('请选择商品');

+ 4 - 1
app/models/system/SystemStore.php

@@ -3,7 +3,9 @@
 
 
 namespace app\models\system;
 namespace app\models\system;
 
 
+use app\admin\model\store\StoreProductAttrValue;
 use app\admin\model\system\SystemStorePoint;
 use app\admin\model\system\SystemStorePoint;
+use app\admin\model\system\SystemStoreProductStock;
 use app\admin\model\system\SystemStoreProductStockLog;
 use app\admin\model\system\SystemStoreProductStockLog;
 use app\models\store\StoreOrderCartInfo;
 use app\models\store\StoreOrderCartInfo;
 use app\models\user\User;
 use app\models\user\User;
@@ -230,7 +232,8 @@ class SystemStore extends BaseModel
 //            exit;
 //            exit;
             $cartNum = $product['cart_num'] ?? 0;
             $cartNum = $product['cart_num'] ?? 0;
             if (isset($product['productInfo'])) {
             if (isset($product['productInfo'])) {
-                $res = $res && SystemStoreProductStockLog::expend($orderInfo['store_id'], $product['product_id'], $product['product_attr_unique'], 'sale', $orderInfo['id'], $cartNum, 0, '用户' . $userInfo['nickname'] . '购买订单完成');
+                $stock = SystemStoreProductStock::where(['product_id' => $product['product_id'], 'unique' => $product['product_attr_unique'], 'store_id' => $orderInfo['store_id']])->find();
+                $res = $res && SystemStoreProductStockLog::expend($orderInfo['store_id'], $product['product_id'], $product['product_attr_unique'], 'sale', $orderInfo['id'], $cartNum, 0, '用户' . $userInfo['nickname'] . '购买订单完成', 1, $stock ? $stock['price'] : StoreProductAttrValue::where(['unique' => $product['product_attr_unique'], 'product_id' => $product['product_id']])->value('price'));
             }
             }
         }
         }
 //        var_dump($res);
 //        var_dump($res);