ItemController.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. //为你推荐
  60. $url .= 'watermark,text_55-z5bCR5Y2OIOS4uuS9oOaOqOiNkA,g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
  61. //标题
  62. $url .= '/watermark,text_6Ieq55Sx5aWz56WeQue6pyDlubTplIDoirE,g_sw,x_18,y_145';
  63. //价格
  64. $url .= '/watermark,text_wqUxMDA,g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
  65. $respond = ['imgUrl' => $url];
  66. util::success($respond);
  67. }
  68. //是否有C级价格大于B级的 ssh 20221204
  69. public function actionGetErrorPrice()
  70. {
  71. $shop = $this->shop;
  72. $list = ItemClass::errorPrice($shop);
  73. util::success(['list' => $list]);
  74. }
  75. //列出所有花材,包括特价花材列表 ssh 20220315
  76. public function actionShowList()
  77. {
  78. $where['mainId'] = $this->mainId;
  79. $where['delStatus'] = 0;
  80. $list = ItemClass::getShowList($where);
  81. util::success(['list' => $list]);
  82. }
  83. public function actionAdd()
  84. {
  85. $post = Yii::$app->request->post();
  86. $post['adminId'] = $this->adminId;
  87. $post['sjId'] = $this->sjId;
  88. $connection = Yii::$app->db;//事务处理
  89. $transaction = $connection->beginTransaction();
  90. try {
  91. ItemService::addGhsItem($post);
  92. $transaction->commit();
  93. util::complete('添加成功');
  94. } catch (Exception $e) {
  95. $transaction->rollBack();
  96. util::fail('添加失败');
  97. }
  98. }
  99. //批量添加花材
  100. public function actionBatchAdd()
  101. {
  102. $shopAdmin = $this->shopAdmin;
  103. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  104. util::fail('超管才能操作');
  105. }
  106. $post = Yii::$app->request->post();
  107. //[{itemId:1000,classId:2,price:1,stockWarning:1}]
  108. $data = $post['data'];
  109. if (empty($data)) {
  110. util::fail("请选花材");
  111. }
  112. $data = json_decode($data, true);
  113. if (!is_array($data) || empty($data)) {
  114. util::fail("请选花材");
  115. }
  116. $sjId = $this->sjId;
  117. $ids = array_column($data, 'itemId');
  118. $ids = array_unique(array_filter($ids));
  119. $has = ProductClass::getByCondition(['sjId' => $sjId, 'itemId' => ['in', $ids]]);
  120. if (!empty($has)) {
  121. util::fail("有花材已经添加过了");
  122. }
  123. $connection = Yii::$app->db;//事务处理
  124. $transaction = $connection->beginTransaction();
  125. try {
  126. foreach ($data as $v) {
  127. $v['adminId'] = $this->adminId;
  128. $v['sjId'] = $sjId;
  129. ItemService::addGhsItem($v);
  130. }
  131. $transaction->commit();
  132. util::complete('添加成功');
  133. } catch (Exception $e) {
  134. $transaction->rollBack();
  135. util::fail();
  136. }
  137. }
  138. public function actionDelete()
  139. {
  140. util::fail('不能删除哦!');
  141. }
  142. //获取平台里的花材信息
  143. public function actionPlatformItem()
  144. {
  145. $py = Yii::$app->request->get('py', '');
  146. $where = [];
  147. if ($py) {
  148. $where = ['py' => $py];
  149. }
  150. $list = PtItemClass::getItemList($where);
  151. util::success($list);
  152. }
  153. //列出需要进行颜色管理的花材 ssh 20220820
  154. public function actionColorList()
  155. {
  156. $mainId = $this->mainId ?? 0;
  157. $list = ItemClass::getAllByCondition(['mainId' => $mainId, 'variety' => 1], null, '*');
  158. util::success(['list' => $list]);
  159. }
  160. //多颜色管理启用与停用 ssh 20221229
  161. public function actionChangeVariety()
  162. {
  163. $get = Yii::$app->request->get();
  164. $id = $get['id'] ?? 0;
  165. $variety = $get['variety'] ?? 0;
  166. $info = ItemClass::getById($id, true);
  167. if (empty($info) || $info->mainId != $this->mainId) {
  168. util::fail('操作失败');
  169. }
  170. $info->variety = $variety;
  171. $info->save();
  172. util::complete('操作成功');
  173. }
  174. //拆散花材 ssh 20221229
  175. public function actionBreakItem()
  176. {
  177. util::fail('开发中');
  178. util::complete();
  179. }
  180. }