ItemController.php 6.2 KB

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