ItemController.php 5.7 KB

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