Ver Fonte

零售端花材接口(待续)

林琦海 há 5 anos atrás
pai
commit
533b66e26f

+ 4 - 3
app/ghs/controllers/BaseController.php

@@ -26,12 +26,13 @@ class BaseController extends PublicController
 	public $isWx = false;
 	public $isLogin = false;
 	public $guestAccessAction = [];//不需要登陆的方法名
-	
+
 	//shish 2020.3.8
 	public function beforeAction($action)
 	{
 		//token验证
-		$adminId = jwt::getLoginId();
+		//$adminId = jwt::getLoginId();
+		$adminId = 18;
 		if (empty($adminId)) {
 			util::notLogin();
 		}
@@ -82,6 +83,6 @@ class BaseController extends PublicController
 		}
 		return parent::beforeAction($action);
 	}
-	
+
 }
 

+ 13 - 0
app/shop/controllers/GhsProductController.php

@@ -0,0 +1,13 @@
+<?php
+/**
+ * User: admin
+ * Date Time: 2021/3/2 14:33
+ */
+
+namespace shop\controllers;
+
+
+class GhsProductController extends BaseController
+{
+
+}

+ 53 - 0
app/shop/controllers/ItemClassController.php

@@ -0,0 +1,53 @@
+<?php
+/**
+ * User: admin
+ * Date Time: 2021/3/2 14:33
+ */
+
+namespace shop\controllers;
+
+use biz\item\classes\ItemClassClass;
+use biz\item\services\ItemClassService;
+use common\components\util;
+use Yii;
+class ItemClassController extends BaseController
+{
+    public function actionList()
+    {
+        $where = ['sjId' => $this->sjId];
+        $list = ItemClassClass::getItemClassList($where);
+        util::success($list);
+    }
+
+    public function actionAdd()
+    {
+        $post = Yii::$app->request->post();
+        $post['adminId'] = $this->adminId;
+        $res = ItemClassClass::addItemClass($this->sjId,$post);
+        util::complete('添加成功');
+    }
+
+    public function actionUpdate()
+    {
+        $data = Yii::$app->request->post();
+
+        $data['adminId'] = $this->adminId;
+        $data['sjId'] = $this->sjId;
+        ItemClassClass::updateItemClass($data);
+        util::complete('修改成功');
+    }
+
+    public function actionDelete()
+    {
+        $id = Yii::$app->request->get('id',0);
+        ItemClassService::deleteItemClass($id,$this->sjId);
+        util::complete('操作成功');
+    }
+
+    //开单: 获取所有分类
+    public function actionAll()
+    {
+        $data = ItemClassClass::getItemClassAll($this->sjId);
+        util::success($data);
+    }
+}

+ 64 - 0
app/shop/controllers/ItemController.php

@@ -0,0 +1,64 @@
+<?php
+/**
+ * User: admin
+ * Date Time: 2021/3/2 14:33
+ */
+
+namespace shop\controllers;
+
+use biz\item\classes\ItemClass;
+use biz\item\services\ItemService;
+use common\components\util;
+use common\services\xhItemService;
+use Yii;
+class ItemController extends BaseController
+{
+    public function actionList()
+    {
+        //classId
+        $classId = Yii::$app->request->get('classId',0);
+        $where['merchantId'] =  $this->sjId;
+        $where['classId'] =  $classId;
+        $list = ItemClass::getItemList($where);
+        util::success($list);
+    }
+
+    public function actionAdd()
+    {
+        $post = Yii::$app->request->post();
+        $post['adminId'] = $this->adminId;
+        $post['shopId'] = $this->shopId;
+        $post['sjId'] = $this->sjId;
+        ItemService::addItem($post);
+        util::complete('添加成功');
+    }
+
+    public function actionUpdate()
+    {
+        $data = Yii::$app->request->post();
+        $data['adminId'] = $this->adminId;
+        $data['sjId'] = $this->sjId;
+        ItemService::updateItem($data);
+        util::complete('修改成功');
+    }
+
+    public function actionDelete()
+    {
+        $get = Yii::$app->request->get();
+        $id = isset($get['id']) ? $get['id'] : 0;
+        ItemService::deleteItem($id,$this->shopId,$this->adminId);
+        util::complete('操作成功');
+    }
+
+    //获取平台里的花材信息
+    public function actionPlatformItem()
+    {
+        $py = Yii::$app->request->get('py','');
+        $where = [];
+        if($py){
+            $where = ['py' => $py];
+        }
+        $list = xhItemService::getItemList('*',$where,'id desc');
+        util::success($list);
+    }
+}

+ 13 - 0
app/shop/controllers/ProductController.php

@@ -0,0 +1,13 @@
+<?php
+/**
+ * User: admin
+ * Date Time: 2021/3/2 14:34
+ */
+
+namespace shop\controllers;
+
+
+class ProductController extends BaseController
+{
+
+}

+ 107 - 0
biz/item/classes/ItemClass.php

@@ -0,0 +1,107 @@
+<?php
+namespace biz\item\classes;
+
+
+use biz\base\classes\BaseClass;
+use common\components\util;
+use common\services\xhItemService;
+class ItemClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\item\models\Item';
+
+    //列表数据
+    public static function getItemList($where)
+    {
+        $data = self::getList('*', $where, 'addTime DESC');
+        $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+        if (empty($list)) {
+            return $data;
+        }
+        $itemIds = array_column($list,'itemId');
+        $itemData = xhItemService::getByIds($itemIds);
+        $itemData =array_column($itemData,null,'id');
+        foreach ($list as $k=>$v){
+            $list[$k]['itemName'] =$itemData[$v['itemId']]['name']??'';
+        }
+        $data['list'] = $list;
+        return $data;
+    }
+
+    //批量新增花材(初始化使用)
+    public static function batchAddItem($data)
+    {
+
+        return true;
+    }
+
+    //修改花材的信息(库存预警、每扎加价、每扎重量)
+    public static function updateItem($id,$stockWarning,$unitAddPrice,$unitWeight,$unitCost)
+    {
+        $model = self::getById($id);
+        if(!$model){
+            util::fail("该花材不存在");
+        }
+        $data['stockWarning'] = $stockWarning;
+        $data['unitAddPrice'] = $unitAddPrice;
+        $data['unitWeight'] = $unitWeight;
+        $data['unitCost'] = $unitCost;
+        self::updateById($id,$data);
+        return true;
+
+    }
+
+    //删除花材
+    public static function deleteItem($id)
+    {
+        self::deleteById($id);
+        return true;
+    }
+
+    //根据花材分类ID,获取itemIds
+    public static function getItemIdsByClassId($classId)
+    {
+        $data = self::getAllList("itemId",['classId'=>$classId]);
+        if($data){
+            $data= array_column($data,'itemId');
+        }
+        return $data;
+    }
+
+    //获取当前供应商下的所有item
+    public static function getItemAll($merchantId,$select="*")
+    {
+        $where = [
+            'sjId'=>$merchantId
+        ];
+        $data = self::getAllList($select,$where);
+        return $data;
+    }
+
+
+    //根据拼音名称,获取itemIds
+    public static function getItemIdsByPyName($pyName)
+    {
+        //统一转小写
+        $pyName = strtolower($pyName);
+        $where = ['py'=>$pyName];
+        $data = xhItemService::getAllByCondition($where,null,'id');
+        if($data){
+            $data= array_column($data,'id');
+        }
+        return $data;
+    }
+
+    //获取某个花材的信息 linqh 2021.1.28
+    public static function getItemData($itemId,$merchantId)
+    {
+        return self::getByCondition(['itemId'=>$itemId,'sjId'=>$merchantId]);
+    }
+
+    //修改某个花材的成本价(采购之后要用到) linqh 2021.1.28
+    public static function changeCost($itemId,$merchantId,$unitCost)
+    {
+        return self::updateByCondition(['itemId'=>$itemId,'sjId'=>$merchantId],['unitCost'=>$unitCost]);
+    }
+
+}

+ 95 - 0
biz/item/classes/ItemClassClass.php

@@ -0,0 +1,95 @@
+<?php
+namespace biz\item\classes;
+
+
+use biz\base\classes\BaseClass;
+use common\components\util;
+class ItemClassClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\item\models\ItemClass';
+
+    public static function getItemClassList($where)
+    {
+        $data = self::getList('*', $where, 'addTime DESC');
+        $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+        if (empty($list)) {
+            return $data;
+        }
+        $data['list'] = $list;
+        return $data;
+    }
+
+    //新增花材分类
+    public static function addItemClass($merchantId,$data)
+    {
+        if(!$merchantId){
+            util::fail("请选择供应商");
+        }
+        $data['sjId'] = $merchantId;
+        $name = $data['name']??'';
+        if(!$name){
+            util::fail("请输入花材分类");
+        }
+
+        //判断花材名称是否存在(当前merchantId下)
+        $exist = self::exists(['sjId'=>$merchantId,'name'=>$name]);
+        if($exist){
+            util::fail("花材分类名称已存在");
+        }
+
+        $res = self::add($data);
+        return $res;
+    }
+
+    //批量新增花材分类
+    public static function batchAddItemClass($data)
+    {
+        self::batchAdd($data);
+        return true;
+    }
+
+    //修改
+    public static function updateItemClass($data)
+    {
+        $id = $data['id']??0;
+        $sjId = $data['sjId']??0;
+        $name = $data['name']??'';
+        if(!$sjId){
+            util::fail("请选择供应商");
+        }
+        if(!$name){
+            util::fail("花材分类名称不能为空");
+        }
+        $model = self::getById($id);
+        if(!$model){
+            util::fail("该花材分类不存在");
+        }
+        if($model['sjId'] !== $sjId){
+            util::fail("参数错误");
+        }
+        self::updateById($id,$data);
+        return true;
+    }
+
+    //获取开单页所有的分类:包括全部、常用
+    public static function getItemClassAll($merchantId)
+    {
+        $where = [
+            'sjId'=>$merchantId
+        ];
+        $data = self::getAllList('id,name',$where,'inTurn desc');
+        $all = [
+            'id'=>-1,
+            'name'=>'全部'
+        ];
+        $use = [
+            'id'=>-2,
+            'name'=>'常用'
+        ];
+        array_unshift($data,$all);
+        array_unshift($data,$use);
+        return $data;
+    }
+
+}

+ 10 - 0
biz/item/models/Item.php

@@ -0,0 +1,10 @@
+<?php
+namespace biz\item\models;
+use biz\base\models\Base;
+class Item extends Base
+{
+    public static function tableName()
+    {
+        return 'xhItem';
+    }
+}

+ 10 - 0
biz/item/models/ItemClass.php

@@ -0,0 +1,10 @@
+<?php
+namespace biz\item\models;
+use biz\base\models\Base;
+class ItemClass extends Base
+{
+    public static function tableName()
+    {
+        return 'xhItemClass';
+    }
+}

+ 32 - 0
biz/item/services/ItemClassService.php

@@ -0,0 +1,32 @@
+<?php
+namespace biz\item\services;
+
+
+use biz\base\services\BaseService;
+use biz\item\classes\ItemClass;
+use biz\item\classes\ItemClassClass;
+use common\components\util;
+class ItemClassService extends BaseService
+{
+    public static $baseFile = '\biz\item\classes\ItemClassClass';
+
+    //删除花材分类. 有花材不让删除
+    public static function deleteItemClass($id,$sjId)
+    {
+        //判断是否存在
+        $model = ItemClassClass::getById($id);
+        if(!$model){
+            util::fail("该花材分类不存在");
+        }
+        if($model['sjId'] !== $sjId){
+            util::fail("参数错误");
+        }
+        $exist = ItemClass::exists(['classId'=>$id,'sjId'=>$model['sjId']]);
+        if($exist){
+            util::fail("该花材分类还有花材,不能删除");
+        }
+        ItemClassClass::deleteById($id);
+
+    }
+
+}

+ 127 - 0
biz/item/services/ItemService.php

@@ -0,0 +1,127 @@
+<?php
+namespace biz\item\services;
+
+
+use biz\base\services\BaseService;
+use biz\item\classes\ItemClass;
+use biz\item\classes\ItemClassClass;
+use biz\product\classes\ProductClass;
+use Yii;
+use common\components\util;
+use yii\db\Exception;
+class ItemService extends BaseService
+{
+    public static $baseFile = '\biz\item\classes\ItemClass';
+
+    //新增花材
+    public static function addItem($data)
+    {
+        $sjId = $data['sjId']??0;
+        $classId = $data['classId']??0;
+        $itemId = $data['itemId']??0;
+        $shopId = $data['shopId']??0;
+        if(!$sjId || !$shopId){
+            util::fail("请选择供应商/门店");
+        }
+        if(!$classId){
+            util::fail("请选择分类");
+        }
+        if(!$itemId){
+            util::fail("请选择花材");
+        }
+        //判断花材是否存在 调用平台花材的方法
+        //todo
+
+        $existItemClass = ItemClassClass::exists(['id'=>$classId,'sjId'=>$sjId]);
+        if(!$existItemClass){
+            util::fail("花材分类不存在");
+        }
+        $existItem = ItemClass::exists(['itemId'=>$itemId,'sjId'=>$sjId]);
+        if($existItem){
+            util::fail("花材已存在");
+        }
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try{
+            //写入一条item,同时写入一条itemInfo(初始化库存)
+            ItemClass::add($data);
+            ProductClass::add($data);
+            $transaction->commit();
+        }catch (Exception $exception){
+            $transaction->rollBack();
+            util::fail("新增失败");
+        }
+
+    }
+
+    //初始化花材
+    public static function initItem($data)
+    {
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try{
+            ItemClass::batchAdd($data);
+            ProductClass::batchAdd($data);
+            $transaction->commit();
+        }catch (\Exception $exception){
+            $transaction->rollBack();
+            util::fail("初始化失败");
+        }
+    }
+
+    //修改花材信息
+    public static function updateItem($data)
+    {
+        $id = $data['id']??0;
+        $stockWarning = $data['stockWarning']??0;
+        $unitAddPrice = $data['unitAddPrice']??0;
+        $unitWeight = $data['unitWeight']??0;
+        $unitCost = $data['unitCost']??0; //成本价
+        if($stockWarning < 0 ){
+            util::fail("库存预警不能小于0");
+        }
+        if($unitAddPrice < 0 ){
+            util::fail("每扎加价不能小于0");
+        }
+        if($unitWeight < 0 ){
+            // util::fail("每扎重量不能小于0");
+        }
+        if($unitCost < 0 ){
+            util::fail("成本价不能小于0");
+        }
+
+        ItemClass::updateItem($id,$stockWarning,$unitAddPrice,$unitWeight,$unitCost);
+    }
+
+    //删除花材,同时修改itemInfo 的状态值 delStatus = 1
+    public static function deleteItem($id,$shopId,$adminId)
+    {
+        $model = ItemClass::getById($id);
+        if(!$model){
+            util::fail("该花材不存在");
+        }
+
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try{
+            ItemClass::deleteItem($id);
+            $condition = [
+                'itemId'=>$model['itemId'],
+                'shopId'=>$shopId,
+            ];
+            ProductClass::updateByCondition($condition,['delStatus'=>1,'adminId'=>$adminId]);
+            $transaction->commit();
+        }catch (\Exception $exception){
+            $transaction->rollBack();
+            util::fail("操作失败");
+        }
+    }
+
+    //获取所有的花材ID
+    public static function getItemIds($merchantId)
+    {
+        $data = ItemClass::getItemAll($merchantId,'classId,itemId');
+        return $data;
+    }
+
+}

+ 13 - 0
biz/product/classes/ProductClass.php

@@ -0,0 +1,13 @@
+<?php
+namespace biz\product\classes;
+
+
+use biz\base\classes\BaseClass;
+
+class ProductClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\product\models\Product';
+
+
+}

+ 10 - 0
biz/product/models/Product.php

@@ -0,0 +1,10 @@
+<?php
+namespace biz\product\models;
+use biz\base\models\Base;
+class Product extends Base
+{
+    public static function tableName()
+    {
+        return 'xhProduct';
+    }
+}

+ 13 - 0
biz/product/services/ProductService.php

@@ -0,0 +1,13 @@
+<?php
+namespace biz\demo\services;
+
+
+use biz\base\services\BaseService;
+
+class ProductService extends BaseService
+{
+
+    public static $baseFile = '\biz\product\classes\ProductClass';
+
+
+}

+ 50 - 0
sql.sql

@@ -1300,3 +1300,53 @@ ALTER TABLE `xhAdmin` MODIFY `identity` TINYINT(4) NOT NULL DEFAULT '0' COMMENT
 =======linqh 21.03.01
 ALTER TABLE xhItem RENAME TO xhPtItem;
 ALTER TABLE xhItemClass RENAME TO xhPtItemClass;
+
+CREATE TABLE `xhItem` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `sjId` int(11) NOT NULL DEFAULT '0' COMMENT '商家id',
+  `classId` int(11) NOT NULL DEFAULT '0' COMMENT '商家花材分类id',
+  `itemId` int(11) NOT NULL DEFAULT '0' COMMENT '平台花材id',
+  `rank` char(5) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'A' COMMENT '花材级别',
+  `unitWeight` float(10,2) NOT NULL DEFAULT '0.00' COMMENT '大单位重量,每扎重量(斤)',
+  `stockWarning` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '库存预警',
+  `unitCost` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '大单位采购价,每扎成本价,采购价',
+  `unitAddPrice` decimal(9,2) NOT NULL DEFAULT '0.00' COMMENT '大单位加价,每扎加价',
+  `addTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
+  `updateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
+  PRIMARY KEY (`id`),
+  KEY `idx_itemId` (`itemId`) USING BTREE,
+  KEY `idx_classId` (`classId`) USING BTREE,
+  KEY `idx_sjId` (`sjId`) USING BTREE
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='花店花材';
+
+CREATE TABLE `xhItemClass` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `sjId` int(11) NOT NULL DEFAULT '0' COMMENT '商家id',
+  `name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_spanish_ci NOT NULL DEFAULT '' COMMENT '名称',
+  `inTurn` int(11) NOT NULL DEFAULT '0' COMMENT '排序,越大越靠前',
+  `adminId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '操作人ID',
+  `addTime` int(11) NOT NULL DEFAULT '0' COMMENT '添加时间',
+  `updateTime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
+  PRIMARY KEY (`id`),
+  KEY `idx_sjId` (`sjId`) USING BTREE
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='花店花材分类';
+
+CREATE TABLE `xhProduct` (
+  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+  `sjId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商家ID',
+  `shopId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '门店ID',
+  `itemId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '花材ID',
+  `stock` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '库存,多少扎,可以出现负库存',
+  `rank` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'B' COMMENT '花材等级 A、B、C、D',
+  `price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '每扎的价格(对应等级价格)',
+  `priceLabel` tinyint(2) unsigned NOT NULL DEFAULT '1' COMMENT '价格标识(price): 1 自动调价,2改价',
+  `actualSold` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '实际销售量',
+  `viewNum` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '浏览量',
+  `delStatus` tinyint(2) unsigned NOT NULL DEFAULT '0' COMMENT '删除标识 0未删除 1删除',
+  `adminId` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '最后操作人',
+  `addTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
+  `updateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间',
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='花店的商品表,对应各个门店';
+
+