ItemController.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. $get = Yii::$app->request->get();
  32. $id = $get['id'] ?? 0;
  33. $item = ItemClass::getById($id, true);
  34. if (empty($item) || $item->mainId != $this->mainId) {
  35. util::fail('获取失败');
  36. }
  37. $cover = $item->cover ?? '';
  38. if (empty($cover)) {
  39. util::fail('获取失败');
  40. }
  41. $merchant = WxOpenClass::getWxInfo();
  42. $page = 'admin/ghsProduct/detail';
  43. $ptStyle = dict::getDict('ptStyle', 'hd');
  44. //scene不能超过32个字条
  45. $scene = "id=" . $id;
  46. $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  47. $prefix = imgUtil::getPrefix();
  48. $itemCover = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
  49. $itemCoverBase64 = base64_encode($itemCover);
  50. //将结果中的加号(+)替换成短划线(-) 将结果中的正斜线(/)替换成下划线(_)将结果中尾部的所有等号(=)省略
  51. $itemCoverBase64 = str_replace('/', '_', $itemCoverBase64);
  52. $itemCoverBase64 = str_replace('+', '-', $itemCoverBase64);
  53. $itemCoverBase64 = rtrim($itemCoverBase64, '=');
  54. $url = $prefix . 'poster/1234.jpg?x-oss-process=image/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
  55. $respond = ['imgUrl' => $url];
  56. util::success($respond);
  57. }
  58. //是否有C级价格大于B级的 ssh 20221204
  59. public function actionGetErrorPrice()
  60. {
  61. $shop = $this->shop;
  62. $list = ItemClass::errorPrice($shop);
  63. util::success(['list' => $list]);
  64. }
  65. //列出所有花材,包括特价花材列表 ssh 20220315
  66. public function actionShowList()
  67. {
  68. $where['mainId'] = $this->mainId;
  69. $where['delStatus'] = 0;
  70. $list = ItemClass::getShowList($where);
  71. util::success(['list' => $list]);
  72. }
  73. public function actionAdd()
  74. {
  75. $post = Yii::$app->request->post();
  76. $post['adminId'] = $this->adminId;
  77. $post['sjId'] = $this->sjId;
  78. $connection = Yii::$app->db;//事务处理
  79. $transaction = $connection->beginTransaction();
  80. try {
  81. ItemService::addGhsItem($post);
  82. $transaction->commit();
  83. util::complete('添加成功');
  84. } catch (Exception $e) {
  85. $transaction->rollBack();
  86. util::fail('添加失败');
  87. }
  88. }
  89. //批量添加花材
  90. public function actionBatchAdd()
  91. {
  92. $shopAdmin = $this->shopAdmin;
  93. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  94. util::fail('超管才能操作');
  95. }
  96. $post = Yii::$app->request->post();
  97. //[{itemId:1000,classId:2,price:1,stockWarning:1}]
  98. $data = $post['data'];
  99. if (empty($data)) {
  100. util::fail("请选花材");
  101. }
  102. $data = json_decode($data, true);
  103. if (!is_array($data) || empty($data)) {
  104. util::fail("请选花材");
  105. }
  106. $sjId = $this->sjId;
  107. $ids = array_column($data, 'itemId');
  108. $ids = array_unique(array_filter($ids));
  109. $has = ProductClass::getByCondition(['sjId' => $sjId, 'itemId' => ['in', $ids]]);
  110. if (!empty($has)) {
  111. util::fail("有花材已经添加过了");
  112. }
  113. $connection = Yii::$app->db;//事务处理
  114. $transaction = $connection->beginTransaction();
  115. try {
  116. foreach ($data as $v) {
  117. $v['adminId'] = $this->adminId;
  118. $v['sjId'] = $sjId;
  119. ItemService::addGhsItem($v);
  120. }
  121. $transaction->commit();
  122. util::complete('添加成功');
  123. } catch (Exception $e) {
  124. $transaction->rollBack();
  125. util::fail();
  126. }
  127. }
  128. public function actionDelete()
  129. {
  130. util::fail('不能删除哦!');
  131. }
  132. //获取平台里的花材信息
  133. public function actionPlatformItem()
  134. {
  135. $py = Yii::$app->request->get('py', '');
  136. $where = [];
  137. if ($py) {
  138. $where = ['py' => $py];
  139. }
  140. $list = PtItemClass::getItemList($where);
  141. util::success($list);
  142. }
  143. //列出需要进行颜色管理的花材 ssh 20220820
  144. public function actionColorList()
  145. {
  146. $mainId = $this->mainId ?? 0;
  147. $list = ItemClass::getAllByCondition(['mainId' => $mainId, 'variety' => 1], null, '*');
  148. util::success(['list' => $list]);
  149. }
  150. //多颜色管理启用与停用 ssh 20221229
  151. public function actionChangeVariety()
  152. {
  153. $get = Yii::$app->request->get();
  154. $id = $get['id'] ?? 0;
  155. $variety = $get['variety'] ?? 0;
  156. $info = ItemClass::getById($id, true);
  157. if (empty($info) || $info->mainId != $this->mainId) {
  158. util::fail('操作失败');
  159. }
  160. $info->variety = $variety;
  161. $info->save();
  162. util::complete('操作成功');
  163. }
  164. //拆散花材 ssh 20221229
  165. public function actionBreakItem()
  166. {
  167. util::fail('开发中');
  168. util::complete();
  169. }
  170. }