ProductController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * User: admin
  4. * Date Time: 2021/1/15 20:36
  5. */
  6. namespace ghs\controllers;
  7. use bizGhs\admin\classes\AdminClass;
  8. use bizGhs\item\classes\ItemClass;
  9. use bizGhs\item\classes\ItemClassClass;
  10. use bizGhs\product\classes\ProductClass;
  11. use bizGhs\product\services\ProductService;
  12. use bizGhs\item\services\ItemService;
  13. use common\components\util;
  14. use Yii;
  15. class ProductController extends BaseController
  16. {
  17. public $guestAccessAction = ['index'];
  18. //开单时获取所有的分类花材信息
  19. //库存预警
  20. public function actionIndex()
  21. {
  22. $py = Yii::$app->request->get('py','');
  23. $type = Yii::$app->request->get('type','');
  24. //访问店铺时用户增加最近访问的店铺 shish 2021.3.1
  25. AdminClass::addRecentShop($this->lookShopId,$this->admin);
  26. //获取所有当前供应商的分类 (全部、常用)
  27. //根据分类组装分类下的花材信息
  28. $classIds = ItemClassClass::getGhsItemClassAll($this->sjId);
  29. //获取供应商下所有花材ID (itemIds)
  30. $itemIdsInfo = ItemService::getGhsItemIds($this->sjId);
  31. $itemIds = array_column($itemIdsInfo,'itemId');
  32. if($py){
  33. $pyNameItemIds = ItemClass::getItemIdsByPyName($py);
  34. $itemIds = array_intersect($itemIds,$pyNameItemIds);
  35. }
  36. $shopId = $this->shopId;
  37. //兼容客户根据门店下单
  38. if($this->lookShopId){
  39. $shopId = $this->lookShopId;
  40. }
  41. //库存预警
  42. if($type=='waring'){
  43. //shopId 改为可以前端传,默认是当前shopId linqh 2021.1.26
  44. $shopId = Yii::$app->request->get('shopId',0);
  45. if(!$shopId){
  46. $shopId = $this->shopId;
  47. }
  48. $waringItemIds = ProductClass::getItemIdsWarning($this->sjId,$shopId);
  49. $itemIds = array_intersect($itemIds,$waringItemIds);
  50. }
  51. $itemInfoData = ProductClass::getProductInfoByItemIds($itemIds,$shopId);
  52. //常用的itemIds
  53. $oftenItemIds = ProductClass::getOftenItemIds($shopId);
  54. //组装数据: [{classId:'','className:'',child:[{itemInfoData}]}]
  55. $data = ProductService::assembleData($classIds,$itemIdsInfo,$itemInfoData,$oftenItemIds);
  56. util::success($data);
  57. }
  58. //弃用
  59. public function actionList()
  60. {
  61. $classId = Yii::$app->request->get('classId',0);
  62. $pyName = Yii::$app->request->get('py','');
  63. $itemIds = ItemClass::getItemIdsByClassId($classId);
  64. if($pyName){
  65. $pyNameItemIds = ItemClass::getItemIdsByPyName($pyName);
  66. $itemIds = array_intersect($itemIds,$pyNameItemIds);
  67. }
  68. $data = ProductClass::getProductInfoByItemIds($itemIds,$this->shopId);
  69. util::success($data);
  70. }
  71. //改价
  72. public function actionChangePrice()
  73. {
  74. $productId = Yii::$app->request->post('productId',0);
  75. $price = Yii::$app->request->post('price');
  76. if(!is_numeric($price)){
  77. util::fail("请输入正确价格");
  78. }
  79. if($price <= 0 ){
  80. util::fail("价格不能小于0");
  81. }
  82. //判断是否有效
  83. $productData = ProductClass::getProductData($productId,$this->shopId);
  84. if(!$productData){
  85. util::fail("花材不存在");
  86. }
  87. ProductClass::changePrice($productId,$this->shopId,$price, ProductClass::PRICE_LABEL_CHANGE);
  88. util::complete("改价成功");
  89. }
  90. //恢复自动调价
  91. public function actionAutoPrice()
  92. {
  93. $productId = Yii::$app->request->post('productId',0);
  94. $productData = ProductClass::getById($productId);
  95. if(!$productData){
  96. util::fail("花材不存在");
  97. }
  98. $itemId = $productData['itemId'];
  99. //获取该花材的每扎成本价和每扎加价
  100. //自动调价=每扎成本价+每扎加价
  101. $itemData = ItemClass::getItemData($itemId,$this->sjId);
  102. if(!$itemData){
  103. util::fail("出错拉");
  104. }
  105. $price = bcadd($itemData['unitCost'],$itemData['unitAddPrice'],2);
  106. ProductClass::changePrice($productId,$this->shopId,$price, ProductClass::PRICE_LABEL_AUTO);
  107. util::complete("操作成功");
  108. }
  109. }