ItemController.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\item\classes\PtItemClass;
  4. use bizGhs\item\classes\ItemClass;
  5. use bizGhs\item\services\ItemService;
  6. use common\components\dict;
  7. use common\components\imgUtil;
  8. use common\components\miniUtil;
  9. use common\components\util;
  10. use bizGhs\product\classes\ProductClass;
  11. use bizHd\wx\classes\WxOpenClass;
  12. use Yii;
  13. class ItemController extends BaseController
  14. {
  15. //获取给散客下单的花材海报 ssh 20220111
  16. public function actionGetSkPoster()
  17. {
  18. $merchant = WxOpenClass::getWxInfo();
  19. $page = 'admin/ghsProduct/detail';
  20. $ptStyle = dict::getDict('ptStyle', 'hd');
  21. //scene不能超过32个字条,这些进行缩写:sId = shopId gId = ghsShopAdminId
  22. $scene = "id=68&gId=123";
  23. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  24. $url = imgUtil::groupImg($imgUrl);
  25. $respond = ['imgUrl' => $url];
  26. util::success($respond);
  27. }
  28. //获取给花店下单的花材海报 ssh 20220111
  29. public function actionGetHdPoster()
  30. {
  31. $merchant = WxOpenClass::getWxInfo();
  32. $page = 'admin/ghsProduct/detail';
  33. $ptStyle = dict::getDict('ptStyle', 'hd');
  34. //scene不能超过32个字条,这些进行缩写:sId = shopId gId = ghsShopAdminId
  35. $scene = "id=68&gId=123";
  36. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  37. $url = imgUtil::groupImg($imgUrl);
  38. $respond = ['imgUrl' => $url];
  39. util::success($respond);
  40. }
  41. //是否有C级价格大于B级的 ssh 20221204
  42. public function actionGetErrorPrice()
  43. {
  44. $shop = $this->shop;
  45. $list = ItemClass::errorPrice($shop);
  46. util::success(['list' => $list]);
  47. }
  48. //列出所有花材,包括特价花材列表 ssh 20220315
  49. public function actionShowList()
  50. {
  51. $where['mainId'] = $this->mainId;
  52. $where['delStatus'] = 0;
  53. $list = ItemClass::getShowList($where);
  54. util::success(['list' => $list]);
  55. }
  56. public function actionAdd()
  57. {
  58. $post = Yii::$app->request->post();
  59. $post['adminId'] = $this->adminId;
  60. $post['sjId'] = $this->sjId;
  61. $connection = Yii::$app->db;//事务处理
  62. $transaction = $connection->beginTransaction();
  63. try {
  64. ItemService::addGhsItem($post);
  65. $transaction->commit();
  66. util::complete('添加成功');
  67. } catch (Exception $e) {
  68. $transaction->rollBack();
  69. util::fail('添加失败');
  70. }
  71. }
  72. //批量添加花材
  73. public function actionBatchAdd()
  74. {
  75. $shopAdmin = $this->shopAdmin;
  76. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  77. util::fail('超管才能操作');
  78. }
  79. $post = Yii::$app->request->post();
  80. //[{itemId:1000,classId:2,price:1,stockWarning:1}]
  81. $data = $post['data'];
  82. if (empty($data)) {
  83. util::fail("请选花材");
  84. }
  85. $data = json_decode($data, true);
  86. if (!is_array($data) || empty($data)) {
  87. util::fail("请选花材");
  88. }
  89. $sjId = $this->sjId;
  90. $ids = array_column($data, 'itemId');
  91. $ids = array_unique(array_filter($ids));
  92. $has = ProductClass::getByCondition(['sjId' => $sjId, 'itemId' => ['in', $ids]]);
  93. if (!empty($has)) {
  94. util::fail("有花材已经添加过了");
  95. }
  96. $connection = Yii::$app->db;//事务处理
  97. $transaction = $connection->beginTransaction();
  98. try {
  99. foreach ($data as $v) {
  100. $v['adminId'] = $this->adminId;
  101. $v['sjId'] = $sjId;
  102. ItemService::addGhsItem($v);
  103. }
  104. $transaction->commit();
  105. util::complete('添加成功');
  106. } catch (Exception $e) {
  107. $transaction->rollBack();
  108. util::fail();
  109. }
  110. }
  111. public function actionDelete()
  112. {
  113. util::fail('不能删除哦!');
  114. }
  115. //获取平台里的花材信息
  116. public function actionPlatformItem()
  117. {
  118. $py = Yii::$app->request->get('py', '');
  119. $where = [];
  120. if ($py) {
  121. $where = ['py' => $py];
  122. }
  123. $list = PtItemClass::getItemList($where);
  124. util::success($list);
  125. }
  126. //列出需要进行颜色管理的花材 ssh 20220820
  127. public function actionColorList()
  128. {
  129. $mainId = $this->mainId ?? 0;
  130. $list = ItemClass::getAllByCondition(['mainId' => $mainId, 'variety' => 1], null, '*');
  131. util::success(['list' => $list]);
  132. }
  133. //多颜色管理启用与停用 ssh 20221229
  134. public function actionChangeVariety()
  135. {
  136. $get = Yii::$app->request->get();
  137. $id = $get['id'] ?? 0;
  138. $variety = $get['variety'] ?? 0;
  139. $info = ItemClass::getById($id, true);
  140. if (empty($info) || $info->mainId != $this->mainId) {
  141. util::fail('操作失败');
  142. }
  143. $info->variety = $variety;
  144. $info->save();
  145. util::complete('操作成功');
  146. }
  147. //拆散花材 ssh 20221229
  148. public function actionBreakItem()
  149. {
  150. util::fail('开发中');
  151. util::complete();
  152. }
  153. }