ItemController.php 10 KB

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