Kirin 3 years ago
parent
commit
c781aab24e

+ 2 - 1
app/admin/controller/company/Goods.php

@@ -112,6 +112,7 @@ class Goods extends AuthController
             ['bar_code', 20],
             ['bar_code', 20],
             ['in_stock', 0],
             ['in_stock', 0],
         ]);
         ]);
+        if (!$this->adminInfo['store_id']) return app('json')->fail('门店铺货用通道');
         if ($where['in_stock'] < 1) return app('json')->fail('补货数量不能少于1');
         if ($where['in_stock'] < 1) return app('json')->fail('补货数量不能少于1');
         $info = SystemStoreStock::alias('a')->join("StoreProduct b", "a.product_id=b.id", "left")->where('a.bar_code', $where['bar_code'])->field('a.price,a.unique,a.in_stock,a.is_consumer,a.product_id,b.store_name,b.image,a.bar_code')->find();
         $info = SystemStoreStock::alias('a')->join("StoreProduct b", "a.product_id=b.id", "left")->where('a.bar_code', $where['bar_code'])->field('a.price,a.unique,a.in_stock,a.is_consumer,a.product_id,b.store_name,b.image,a.bar_code')->find();
         if (!$info) {
         if (!$info) {
@@ -119,7 +120,7 @@ class Goods extends AuthController
             if (!$store_product)
             if (!$store_product)
                 return app('json')->fail('商品条形码不存在');
                 return app('json')->fail('商品条形码不存在');
             SystemStoreStock::create([
             SystemStoreStock::create([
-                    'store_id' => $this->adminInfo['store_id'] ?: 1,
+                    'store_id' => $this->adminInfo['store_id'],
                     'product_id' => $store_product['product_id'],
                     'product_id' => $store_product['product_id'],
                     'in_stock' => 0,
                     'in_stock' => 0,
                     'store_sales' => 0,
                     'store_sales' => 0,

+ 91 - 90
app/admin/controller/store/StoreProduct.php

@@ -50,40 +50,42 @@ class StoreProduct extends AuthController
         //获取分类
         //获取分类
         $this->assign('cate', CategoryModel::getTierList(null, 1));
         $this->assign('cate', CategoryModel::getTierList(null, 1));
         //出售中产品
         //出售中产品
-        $onsale = ProductModel::where('is_del', 0)->where('is_consumer',0)->where('is_show', 1)->count();
+        $onsale = ProductModel::where('is_del', 0)->where('is_consumer', 0)->where('is_show', 1)->count();
         //待上架产品
         //待上架产品
-        $forsale = ProductModel::where('is_del', 0)->where('is_consumer',0)->where('is_show', 0)->count();
+        $forsale = ProductModel::where('is_del', 0)->where('is_consumer', 0)->where('is_show', 0)->count();
         //仓库中产品
         //仓库中产品
-        $warehouse = ProductModel::where('is_del', 0)->where('is_consumer',0)->count();
+        $warehouse = ProductModel::where('is_del', 0)->where('is_consumer', 0)->count();
         //已经售馨产品
         //已经售馨产品
-        $outofstock = ProductModel::getModelObject(['type' => 4])->where('is_consumer',0)->count();
+        $outofstock = ProductModel::getModelObject(['type' => 4])->where('is_consumer', 0)->count();
         //警戒库存
         //警戒库存
-        $policeforce = ProductModel::getModelObject(['type' => 5])->where('is_consumer',0)->count();
+        $policeforce = ProductModel::getModelObject(['type' => 5])->where('is_consumer', 0)->count();
         //回收站
         //回收站
-        $recycle = ProductModel::where('is_del', 1)->where('is_consumer',0)->count();
+        $recycle = ProductModel::where('is_del', 1)->where('is_consumer', 0)->count();
         $this->assign(compact('type', 'onsale', 'forsale', 'warehouse', 'outofstock', 'policeforce', 'recycle'));
         $this->assign(compact('type', 'onsale', 'forsale', 'warehouse', 'outofstock', 'policeforce', 'recycle'));
         return $this->fetch();
         return $this->fetch();
     }
     }
+
     public function consumer()
     public function consumer()
     {
     {
         $type = $this->request->param('type', 1);
         $type = $this->request->param('type', 1);
         //获取分类
         //获取分类
-        $this->assign('cate', CategoryModel::getTierList(null, 1,1));
+        $this->assign('cate', CategoryModel::getTierList(null, 1, 1));
         //出售中产品
         //出售中产品
-        $onsale = ProductModel::where('is_del', 0)->where('is_show', 1)->where('is_consumer',1)->count();
+        $onsale = ProductModel::where('is_del', 0)->where('is_show', 1)->where('is_consumer', 1)->count();
         //待上架产品
         //待上架产品
-        $forsale = ProductModel::where('is_del', 0)->where('is_show', 0)->where('is_consumer',1)->count();
+        $forsale = ProductModel::where('is_del', 0)->where('is_show', 0)->where('is_consumer', 1)->count();
         //仓库中产品
         //仓库中产品
-        $warehouse = ProductModel::where('is_del', 0)->where('is_consumer',1)->count();
+        $warehouse = ProductModel::where('is_del', 0)->where('is_consumer', 1)->count();
         //已经售馨产品
         //已经售馨产品
-        $outofstock = ProductModel::getModelObject(['type' => 4])->where('is_consumer',1)->count();
+        $outofstock = ProductModel::getModelObject(['type' => 4])->where('is_consumer', 1)->count();
         //警戒库存
         //警戒库存
-        $policeforce = ProductModel::getModelObject(['type' => 5])->where('is_consumer',1)->count();
+        $policeforce = ProductModel::getModelObject(['type' => 5])->where('is_consumer', 1)->count();
         //回收站
         //回收站
-        $recycle = ProductModel::where('is_del', 1)->where('is_consumer',1)->count();
+        $recycle = ProductModel::where('is_del', 1)->where('is_consumer', 1)->count();
         $this->assign(compact('type', 'onsale', 'forsale', 'warehouse', 'outofstock', 'policeforce', 'recycle'));
         $this->assign(compact('type', 'onsale', 'forsale', 'warehouse', 'outofstock', 'policeforce', 'recycle'));
         return $this->fetch();
         return $this->fetch();
     }
     }
+
     /**
     /**
      * 异步查找产品
      * 异步查找产品
      *
      *
@@ -99,7 +101,7 @@ class StoreProduct extends AuthController
             ['excel', 0],
             ['excel', 0],
             ['order', ''],
             ['order', ''],
             [['type', 'd'], $this->request->param('type/d')],
             [['type', 'd'], $this->request->param('type/d')],
-            ['is_consumer',0]
+            ['is_consumer', 0]
         ]);
         ]);
         return Json::successlayui(ProductModel::ProductList($where));
         return Json::successlayui(ProductModel::ProductList($where));
     }
     }
@@ -160,7 +162,7 @@ class StoreProduct extends AuthController
      *
      *
      * @return \think\Response
      * @return \think\Response
      */
      */
-    public function create($id = 0,$consumer=0)
+    public function create($id = 0, $consumer = 0)
     {
     {
         $this->assign('id', (int)$id);
         $this->assign('id', (int)$id);
         $this->assign('consumer', (int)$consumer);
         $this->assign('consumer', (int)$consumer);
@@ -187,9 +189,9 @@ class StoreProduct extends AuthController
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      * @throws \think\db\exception\ModelNotFoundException
      */
      */
-    public function get_product_info($id = 0,$type=0)
+    public function get_product_info($id = 0, $type = 0)
     {
     {
-        $list = CategoryModel::getTierList(null, 1,$type);
+        $list = CategoryModel::getTierList(null, 1, $type);
         $menus = [];
         $menus = [];
         foreach ($list as $menu) {
         foreach ($list as $menu) {
             $menus[] = ['value' => $menu['id'], 'label' => $menu['html'] . $menu['cate_name'], 'disabled' => $menu['pid'] == 0 ? 0 : 1];//,'disabled'=>$menu['pid']== 0];
             $menus[] = ['value' => $menu['id'], 'label' => $menu['html'] . $menu['cate_name'], 'disabled' => $menu['pid'] == 0 ? 0 : 1];//,'disabled'=>$menu['pid']== 0];
@@ -298,8 +300,8 @@ class StoreProduct extends AuthController
             ['items', []],
             ['items', []],
             ['attrs', []],
             ['attrs', []],
             ['activity', []],
             ['activity', []],
-            ['is_consumer',0],
-            ['bar_code',''],
+            ['is_consumer', 0],
+            ['bar_code', ''],
         ]);
         ]);
         foreach ($data['activity'] as $k => $v) {
         foreach ($data['activity'] as $k => $v) {
             if ($v == '秒杀') {
             if ($v == '秒杀') {
@@ -403,71 +405,73 @@ class StoreProduct extends AuthController
     {
     {
         $where = Util::getMore([
         $where = Util::getMore([
             ['bar_code', 20],
             ['bar_code', 20],
-            ['in_stock',0],
+            ['in_stock', 0],
         ]);
         ]);
-        if($where['in_stock']<1) return app('json')->fail('补货数量不能少于1');
-        $info =  StoreProductAttrValue::alias('a')->join("StoreProduct b","a.product_id=b.id","left")->where('a.bar_code',$where['bar_code'])->field('a.price,a.unique,a.stock as in_stock,a.product_id,b.store_name,b.image,a.bar_code')->find();
-        if(!$info) return app('json')->fail('商品条形码不存在');
+        if ($where['in_stock'] < 1) return app('json')->fail('补货数量不能少于1');
+        $info = StoreProductAttrValue::alias('a')->join("StoreProduct b", "a.product_id=b.id", "left")->where('a.bar_code', $where['bar_code'])->field('a.price,a.unique,a.stock as in_stock,a.product_id,b.store_name,b.image,a.bar_code')->find();
+        if (!$info) return app('json')->fail('商品条形码不存在');
         $info = $info->toarray();
         $info = $info->toarray();
         $info['in_stock'] = $where['in_stock'];
         $info['in_stock'] = $where['in_stock'];
         $info['admin_id'] = $this->adminId;
         $info['admin_id'] = $this->adminId;
-        if(SystemStockBill::order_create($info))
-        {
+        if (SystemStockBill::order_create($info)) {
             return Json::successful('入库成功');
             return Json::successful('入库成功');
-        }
-        else
-        {
+        } else {
             return Json::fail('入库失败');
             return Json::fail('入库失败');
         }
         }
     }
     }
+
     public function bill()
     public function bill()
     {
     {
         return $this->fetch();
         return $this->fetch();
     }
     }
+
     public function bill_lst()
     public function bill_lst()
     {
     {
         $where = Util::getMore([
         $where = Util::getMore([
-            ['key',''],
-            ['page',0],
-            ['limit',0],
-            ['status',-2],
+            ['key', ''],
+            ['page', 0],
+            ['limit', 0],
+            ['status', -2],
         ]);
         ]);
         return Json::successlayui(SystemStockBill::lst($where));
         return Json::successlayui(SystemStockBill::lst($where));
     }
     }
+
     public function audit($id)
     public function audit($id)
     {
     {
         if (!$id) return $this->failed('数据不存在');
         if (!$id) return $this->failed('数据不存在');
-        $Bill = SystemStockBill::where('id',$id)->find();
+        $Bill = SystemStockBill::where('id', $id)->find();
         if (!$Bill) return Json::fail('数据不存在!');
         if (!$Bill) return Json::fail('数据不存在!');
         $f = array();
         $f = array();
         $f[] = Form::radio('status', '状态', $Bill->getData('status'))->options([['value' => 1, 'label' => '通过'], ['value' => -1, 'label' => '拒绝']]);
         $f[] = Form::radio('status', '状态', $Bill->getData('status'))->options([['value' => 1, 'label' => '通过'], ['value' => -1, 'label' => '拒绝']]);
-        $f[] = Form::textarea('refuse_msg','备注');
+        $f[] = Form::textarea('refuse_msg', '备注');
         $form = Form::make_post_form('入库审核', $f, Url::buildUrl('audit_save', array('id' => $id)), 2);
         $form = Form::make_post_form('入库审核', $f, Url::buildUrl('audit_save', array('id' => $id)), 2);
         $this->assign(compact('form'));
         $this->assign(compact('form'));
         return $this->fetch('public/form-builder');
         return $this->fetch('public/form-builder');
     }
     }
+
     public function batch_audit($id)
     public function batch_audit($id)
     {
     {
         if (!$id) return $this->failed('数据不存在');
         if (!$id) return $this->failed('数据不存在');
 
 
         $f = array();
         $f = array();
         $f[] = Form::radio('status', '状态')->options([['value' => 1, 'label' => '通过'], ['value' => -1, 'label' => '拒绝']]);
         $f[] = Form::radio('status', '状态')->options([['value' => 1, 'label' => '通过'], ['value' => -1, 'label' => '拒绝']]);
-        $f[] = Form::textarea('refuse_msg','备注');
+        $f[] = Form::textarea('refuse_msg', '备注');
         $form = Form::make_post_form('入库审核', $f, Url::buildUrl('batch_audit_save', array('id' => $id)), 2);
         $form = Form::make_post_form('入库审核', $f, Url::buildUrl('batch_audit_save', array('id' => $id)), 2);
         $this->assign(compact('form'));
         $this->assign(compact('form'));
         return $this->fetch('public/form-builder');
         return $this->fetch('public/form-builder');
     }
     }
+
     public function audit_save($id)
     public function audit_save($id)
     {
     {
         $where = Util::postMore([
         $where = Util::postMore([
-            ['refuse_msg',''],
-            ['status',1],
+            ['refuse_msg', ''],
+            ['status', 1],
         ]);
         ]);
-        if(!SystemStockBill::be(['id'=>$id,'status'=>0])) return $this->failed('数据不存在或已经审核');
+        if (!SystemStockBill::be(['id' => $id, 'status' => 0])) return $this->failed('数据不存在或已经审核');
         $where['audit_time'] = time();
         $where['audit_time'] = time();
         $where['audit_admin'] = $this->adminId;
         $where['audit_admin'] = $this->adminId;
-        SystemStockBill::edit($where,$id);
-        if($where['status']==1) {
+        SystemStockBill::edit($where, $id);
+        if ($where['status'] == 1) {
             $info = SystemStockBill::find($id)->toArray();
             $info = SystemStockBill::find($id)->toArray();
             $rs = StoreProductAttrValue::in_Stock($info);
             $rs = StoreProductAttrValue::in_Stock($info);
         }
         }
@@ -480,26 +484,24 @@ class StoreProduct extends AuthController
     public function batch_audit_save()
     public function batch_audit_save()
     {
     {
         $where = Util::postMore([
         $where = Util::postMore([
-            ['refuse_msg',''],
-            ['status',1],
+            ['refuse_msg', ''],
+            ['status', 1],
         ]);
         ]);
-        $ids = explode(',',input('id'));
-        if($where['status']==1)
-        {
-            foreach ($ids as $v)
-            {
-                $info = SystemStockBill::where('id',$v)->where('status',0)->find();
-                if($info)
-                {
+        $ids = explode(',', input('id'));
+        if ($where['status'] == 1) {
+            foreach ($ids as $v) {
+                $info = SystemStockBill::where('id', $v)->where('status', 0)->find();
+                if ($info) {
                     $rs = StoreProductAttrValue::in_Stock($info);
                     $rs = StoreProductAttrValue::in_Stock($info);
                 }
                 }
             }
             }
         }
         }
         $where['audit_time'] = time();
         $where['audit_time'] = time();
         $where['audit_admin'] = $this->adminId;
         $where['audit_admin'] = $this->adminId;
-        SystemStockBill::where('id','in',join(",",$ids))->update($where);
+        SystemStockBill::where('id', 'in', join(",", $ids))->update($where);
         return Json::successful('批量审核成功');
         return Json::successful('批量审核成功');
     }
     }
+
     public function edit_content($id)
     public function edit_content($id)
     {
     {
         if (!$id) return $this->failed('数据不存在');
         if (!$id) return $this->failed('数据不存在');
@@ -850,57 +852,56 @@ class StoreProduct extends AuthController
             return Json::fail('没有参数ID');
             return Json::fail('没有参数ID');
         }
         }
     }
     }
+
     public function product_br()
     public function product_br()
     {
     {
-        $list = StoreProductAttrValue::where('bar_code','<','99999')->where('volume','>','0')->column('product_id,bar_code,price,volume');
+        $list = StoreProductAttrValue::where('bar_code', '<', '99999')->where('volume', '>', '0')->column('product_id,bar_code,price,volume');
         $str = "";
         $str = "";
-        foreach ($list as $v)
-        {
-            $title = ProductModel::where('id',$v['product_id'])->value('store_name');
-            $str.=sprintf("PLU\t%d\t%s\t\t%s\t%s\t1\t1\t999\t\t\r\n",$v['volume'],$v['bar_code'],$title,bcadd($v['price'],0,2));
+        foreach ($list as $v) {
+            $title = ProductModel::where('id', $v['product_id'])->value('store_name');
+            $str .= sprintf("PLU\t%d\t%s\t\t%s\t%s\t1\t1\t999\t\t\r\n", $v['volume'], $v['bar_code'], $title, bcadd($v['price'], 0, 2));
         }
         }
-       $str = $this->charsetToGBK($str);
-header("Content-type: text/plain; charset=gbk");
-header("Accept-Ranges: bytes");
-header("Content-Disposition: attachment; filename=NewFile.txt");
-header("Cache-Control: must-revalidate, post-check=0, pre-check=0" );
-header("Pragma: no-cache" );
-header("Expires: 0" );
-exit($str); 
+        $str = $this->charsetToGBK($str);
+        header("Content-type: text/plain; charset=gbk");
+        header("Accept-Ranges: bytes");
+        header("Content-Disposition: attachment; filename=NewFile.txt");
+        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
+        header("Pragma: no-cache");
+        header("Expires: 0");
+        exit($str);
 
 
 
 
     }
     }
+
     /**
     /**
- * 将非GBK字符集的编码转为GBK
- *
- * @param mixed $mixed 源数据
- *
- * @return mixed GBK格式数据
- */
-function charsetToGBK($mixed)
-{
-    if (is_array($mixed)) {
-        foreach ($mixed as $k => $v) {
-            if (is_array($v)) {
-                $mixed[$k] = charsetToGBK($v);
-            } else {
-                $encode = mb_detect_encoding($v, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5'));
-                if ($encode == 'UTF-8') {
-                    $mixed[$k] = iconv('UTF-8', 'GBK', $v);
+     * 将非GBK字符集的编码转为GBK
+     *
+     * @param mixed $mixed 源数据
+     *
+     * @return mixed GBK格式数据
+     */
+    function charsetToGBK($mixed)
+    {
+        if (is_array($mixed)) {
+            foreach ($mixed as $k => $v) {
+                if (is_array($v)) {
+                    $mixed[$k] = charsetToGBK($v);
+                } else {
+                    $encode = mb_detect_encoding($v, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5'));
+                    if ($encode == 'UTF-8') {
+                        $mixed[$k] = iconv('UTF-8', 'GBK', $v);
+                    }
                 }
                 }
             }
             }
+        } else {
+            $encode = mb_detect_encoding($mixed, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5'));
+            //var_dump($encode);
+            if ($encode == 'UTF-8') {
+                $mixed = iconv('UTF-8', 'GBK', $mixed);
+            }
         }
         }
-    } else {
-        $encode = mb_detect_encoding($mixed, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5'));
-        //var_dump($encode);
-        if ($encode == 'UTF-8') {
-            $mixed = iconv('UTF-8', 'GBK', $mixed);
-        }
+        return $mixed;
     }
     }
-    return $mixed;
-}
- 
- 
 
 
 
 
 }
 }

+ 6 - 4
app/admin/model/store/StoreProductAttrValue.php

@@ -48,23 +48,25 @@ class StoreProductAttrValue extends BaseModel
         if ($productAttr->sales < 0) $productAttr->sales = 0;
         if ($productAttr->sales < 0) $productAttr->sales = 0;
         $productAttr->stock = bcadd($productAttr->stock, $num, 0);
         $productAttr->stock = bcadd($productAttr->stock, $num, 0);
         //活动商品有限量数
         //活动商品有限量数
-        if($type > 0){
+        if ($type > 0) {
             $productAttr->quota = bcadd($productAttr->quota, $num, 0);
             $productAttr->quota = bcadd($productAttr->quota, $num, 0);
         }
         }
         return $productAttr->save();
         return $productAttr->save();
     }
     }
+
     public static function in_Stock($info)
     public static function in_Stock($info)
     {
     {
         self::beginTrans();
         self::beginTrans();
         try {
         try {
-            StoreProduct::where('id',$info['product_id'])->inc('stock',$info['in_stock'])->update();
-            self::where('product_id',$info['product_id'])->where('bar_code',$info['bar_code'])->inc('stock',$info['in_stock'])->update();
+            StoreProduct::where('id', $info['product_id'])->inc('stock', $info['in_stock'])->update();
+            self::where('product_id', $info['product_id'])->where('bar_code', $info['bar_code'])->inc('stock', $info['in_stock'])->update();
             self::commitTrans();
             self::commitTrans();
         } catch (Exception $e) {
         } catch (Exception $e) {
-            self::setErrorInfo($e->getMessage(),true);
+            self::setErrorInfo($e->getMessage(), true);
         }
         }
         return true;
         return true;
     }
     }
+
     public static function decProductAttrStock($productId, $unique, $num, $type = 0)
     public static function decProductAttrStock($productId, $unique, $num, $type = 0)
     {
     {
         if ($type == 0) {
         if ($type == 0) {