ItemController.php 9.8 KB

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