ItemController.php 9.9 KB

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