ItemController.php 6.9 KB

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