ItemController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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 20230206
  17. public function actionBatchRecover()
  18. {
  19. util::complete('操作成功');
  20. }
  21. //批量删除花材 ssh 202302026
  22. public function actionBatchRemove()
  23. {
  24. util::complete('操作成功');
  25. }
  26. //批量启用花材 ssh 20230206
  27. public function actionBatchEnable()
  28. {
  29. util::complete('操作成功');
  30. }
  31. //批量停用花材 20230206
  32. public function actionBatchStop()
  33. {
  34. util::complete('操作成功');
  35. }
  36. //获取给散客下单的花材海报 ssh 20220111
  37. public function actionGetSkPoster()
  38. {
  39. $get = Yii::$app->request->get();
  40. $id = $get['id'] ?? 0;
  41. $item = ItemClass::getById($id, true);
  42. if (empty($item) || $item->mainId != $this->mainId) {
  43. util::fail('获取失败');
  44. }
  45. $cover = $item->cover ?? '';
  46. if (empty($cover)) {
  47. util::fail('获取失败');
  48. }
  49. $merchant = WxOpenClass::getMallWxInfo();
  50. $page = 'pages/item/detail';
  51. $ptStyle = dict::getDict('ptStyle', 'mall');
  52. $shop = $this->shop;
  53. $lsShopId = $shop->lsShopId ?? 0;
  54. //scene不能超过32个字条
  55. $scene = "id=" . $id . '&a=' . $lsShopId;
  56. $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  57. $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
  58. $miniCodeBase64 = stringUtil::ossBase64($miniCode);
  59. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
  60. $prefix = imgUtil::getPrefix();
  61. $price = $item->skPrice ?? 0;
  62. if ($item->discountPrice > 0) {
  63. $skMore = $item->skMore ?? 0;
  64. $price = bcadd($item->discountPrice, $skMore, 2);
  65. }
  66. $newPrice = '¥' . floatval($price);
  67. $priceBase64 = stringUtil::ossBase64($newPrice);
  68. $name = $item->name ?? '';
  69. $nameBase64 = stringUtil::ossBase64($name);
  70. $staff = $this->shopAdmin;
  71. $staffName = $staff->name ?? '';
  72. $newStaffName = $staffName . ' 为您推荐';
  73. $staffNameBase64 = stringUtil::ossBase64($newStaffName);
  74. //花材主图
  75. $itemCover = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
  76. $itemCoverBase64 = stringUtil::ossBase64($itemCover);
  77. $logoBase64 = '';
  78. if (in_array($this->mainId, [52, 1459])) {
  79. $logo = 'poster/hyxh_ncd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  80. if ($this->mainId == 1459) {
  81. $logo = 'poster/hyxh_gcd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  82. }
  83. $logoBase64 = stringUtil::ossBase64($logo);
  84. }
  85. $url = $prefix . 'poster/1234.jpg?x-oss-process=image';
  86. //花材主图
  87. $url .= '/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
  88. //小程序码
  89. $url .= '/watermark,image_' . $miniCodeBase64 . ',g_se';
  90. if (!empty($logoBase64)) {
  91. //logo
  92. $url .= '/watermark,image_' . $logoBase64 . ',g_se,x_65,y_65';
  93. }
  94. //为你推荐
  95. $url .= '/watermark,text_' . $staffNameBase64 . ',g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
  96. //标题
  97. $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
  98. //价格
  99. $url .= '/watermark,text_' . $priceBase64 . ',g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
  100. $respond = ['imgUrl' => $url];
  101. util::success($respond);
  102. }
  103. //获取给花店下单的花材海报 ssh 20220111
  104. public function actionGetHdPoster()
  105. {
  106. $get = Yii::$app->request->get();
  107. $id = $get['id'] ?? 0;
  108. $item = ItemClass::getById($id, true);
  109. if (empty($item) || $item->mainId != $this->mainId) {
  110. util::fail('获取失败');
  111. }
  112. $cover = $item->cover ?? '';
  113. if (empty($cover)) {
  114. util::fail('获取失败');
  115. }
  116. $merchant = WxOpenClass::getWxInfo();
  117. $page = 'admin/ghsProduct/detail';
  118. $ptStyle = dict::getDict('ptStyle', 'hd');
  119. //小程序码,scene不能超过32个字条
  120. $scene = "id=" . $id . '&sId=' . $this->shopId;
  121. $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  122. $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
  123. $miniCodeBase64 = stringUtil::ossBase64($miniCode);
  124. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  125. $prefix = imgUtil::getPrefix();
  126. $price = $item->price ?? 0;
  127. if ($item->discountPrice > 0) {
  128. $price = $item->discountPrice;
  129. }
  130. $newPrice = '¥' . floatval($price);
  131. $priceBase64 = stringUtil::ossBase64($newPrice);
  132. $name = $item->name ?? '';
  133. $nameBase64 = stringUtil::ossBase64($name);
  134. $staff = $this->shopAdmin;
  135. $staffName = $staff->name ?? '';
  136. $newStaffName = $staffName . ' 为您推荐';
  137. $staffNameBase64 = stringUtil::ossBase64($newStaffName);
  138. //花材主图
  139. $itemCover = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
  140. $itemCoverBase64 = stringUtil::ossBase64($itemCover);
  141. $logoBase64 = '';
  142. if (in_array($this->mainId, [52, 1459])) {
  143. $logo = 'poster/hyxh_ncd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  144. if ($this->mainId == 1459) {
  145. $logo = 'poster/hyxh_gcd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  146. }
  147. $logoBase64 = stringUtil::ossBase64($logo);
  148. }
  149. $url = $prefix . 'poster/1234.jpg?x-oss-process=image';
  150. //花材主图
  151. $url .= '/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
  152. //小程序码
  153. $url .= '/watermark,image_' . $miniCodeBase64 . ',g_se';
  154. if (!empty($logoBase64)) {
  155. //logo
  156. $url .= '/watermark,image_' . $logoBase64 . ',g_se,x_65,y_65';
  157. }
  158. //为你推荐
  159. $url .= '/watermark,text_' . $staffNameBase64 . ',g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
  160. //标题
  161. $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
  162. //价格
  163. $url .= '/watermark,text_' . $priceBase64 . ',g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
  164. $respond = ['imgUrl' => $url];
  165. util::success($respond);
  166. }
  167. //是否有C级价格大于B级的 ssh 20221204
  168. public function actionGetErrorPrice()
  169. {
  170. $shop = $this->shop;
  171. $list = ItemClass::errorPrice($shop);
  172. util::success(['list' => $list]);
  173. }
  174. //列出所有花材,包括特价花材列表 ssh 20220315
  175. public function actionShowList()
  176. {
  177. $where['mainId'] = $this->mainId;
  178. $where['delStatus'] = 0;
  179. $list = ItemClass::getShowList($where);
  180. util::success(['list' => $list]);
  181. }
  182. public function actionAdd()
  183. {
  184. $post = Yii::$app->request->post();
  185. $post['adminId'] = $this->adminId;
  186. $post['sjId'] = $this->sjId;
  187. $connection = Yii::$app->db;//事务处理
  188. $transaction = $connection->beginTransaction();
  189. try {
  190. ItemService::addGhsItem($post);
  191. $transaction->commit();
  192. util::complete('添加成功');
  193. } catch (Exception $e) {
  194. $transaction->rollBack();
  195. util::fail('添加失败');
  196. }
  197. }
  198. //批量添加花材
  199. public function actionBatchAdd()
  200. {
  201. $shopAdmin = $this->shopAdmin;
  202. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  203. util::fail('超管才能操作');
  204. }
  205. $post = Yii::$app->request->post();
  206. //[{itemId:1000,classId:2,price:1,stockWarning:1}]
  207. $data = $post['data'];
  208. if (empty($data)) {
  209. util::fail("请选花材");
  210. }
  211. $data = json_decode($data, true);
  212. if (!is_array($data) || empty($data)) {
  213. util::fail("请选花材");
  214. }
  215. $sjId = $this->sjId;
  216. $ids = array_column($data, 'itemId');
  217. $ids = array_unique(array_filter($ids));
  218. $has = ProductClass::getByCondition(['sjId' => $sjId, 'itemId' => ['in', $ids]]);
  219. if (!empty($has)) {
  220. util::fail("有花材已经添加过了");
  221. }
  222. $connection = Yii::$app->db;//事务处理
  223. $transaction = $connection->beginTransaction();
  224. try {
  225. foreach ($data as $v) {
  226. $v['adminId'] = $this->adminId;
  227. $v['sjId'] = $sjId;
  228. ItemService::addGhsItem($v);
  229. }
  230. $transaction->commit();
  231. util::complete('添加成功');
  232. } catch (Exception $e) {
  233. $transaction->rollBack();
  234. util::fail();
  235. }
  236. }
  237. public function actionDelete()
  238. {
  239. util::fail('不能删除哦!');
  240. }
  241. //获取平台里的花材信息
  242. public function actionPlatformItem()
  243. {
  244. $py = Yii::$app->request->get('py', '');
  245. $where = [];
  246. if ($py) {
  247. $where = ['py' => $py];
  248. }
  249. $list = PtItemClass::getItemList($where);
  250. util::success($list);
  251. }
  252. //列出需要进行颜色管理的花材 ssh 20220820
  253. public function actionColorList()
  254. {
  255. $mainId = $this->mainId ?? 0;
  256. $list = ItemClass::getAllByCondition(['mainId' => $mainId, 'variety' => 1], null, '*');
  257. util::success(['list' => $list]);
  258. }
  259. //多颜色管理启用与停用 ssh 20221229
  260. public function actionChangeVariety()
  261. {
  262. $get = Yii::$app->request->get();
  263. $id = $get['id'] ?? 0;
  264. $variety = $get['variety'] ?? 0;
  265. $info = ItemClass::getById($id, true);
  266. if (empty($info) || $info->mainId != $this->mainId) {
  267. util::fail('操作失败');
  268. }
  269. $info->variety = $variety;
  270. $info->save();
  271. util::complete('操作成功');
  272. }
  273. //拆散花材 ssh 20221229
  274. public function actionBreakItem()
  275. {
  276. util::fail('开发中');
  277. util::complete();
  278. }
  279. }