ItemController.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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_98,w_98';
  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';
  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. $url = $prefix . 'poster/1234.jpg?x-oss-process=image';
  128. //花材主图
  129. $url .= '/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
  130. //小程序码
  131. $url .= '/watermark,image_' . $miniCodeBase64 . ',g_se';
  132. //为你推荐
  133. $url .= '/watermark,text_' . $staffNameBase64 . ',g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
  134. //标题
  135. $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
  136. //价格
  137. $url .= '/watermark,text_' . $priceBase64 . ',g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
  138. $respond = ['imgUrl' => $url];
  139. util::success($respond);
  140. }
  141. //是否有C级价格大于B级的 ssh 20221204
  142. public function actionGetErrorPrice()
  143. {
  144. $shop = $this->shop;
  145. $list = ItemClass::errorPrice($shop);
  146. util::success(['list' => $list]);
  147. }
  148. //列出所有花材,包括特价花材列表 ssh 20220315
  149. public function actionShowList()
  150. {
  151. $where['mainId'] = $this->mainId;
  152. $where['delStatus'] = 0;
  153. $list = ItemClass::getShowList($where);
  154. util::success(['list' => $list]);
  155. }
  156. public function actionAdd()
  157. {
  158. $post = Yii::$app->request->post();
  159. $post['adminId'] = $this->adminId;
  160. $post['sjId'] = $this->sjId;
  161. $connection = Yii::$app->db;//事务处理
  162. $transaction = $connection->beginTransaction();
  163. try {
  164. ItemService::addGhsItem($post);
  165. $transaction->commit();
  166. util::complete('添加成功');
  167. } catch (Exception $e) {
  168. $transaction->rollBack();
  169. util::fail('添加失败');
  170. }
  171. }
  172. //批量添加花材
  173. public function actionBatchAdd()
  174. {
  175. $shopAdmin = $this->shopAdmin;
  176. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  177. util::fail('超管才能操作');
  178. }
  179. $post = Yii::$app->request->post();
  180. //[{itemId:1000,classId:2,price:1,stockWarning:1}]
  181. $data = $post['data'];
  182. if (empty($data)) {
  183. util::fail("请选花材");
  184. }
  185. $data = json_decode($data, true);
  186. if (!is_array($data) || empty($data)) {
  187. util::fail("请选花材");
  188. }
  189. $sjId = $this->sjId;
  190. $ids = array_column($data, 'itemId');
  191. $ids = array_unique(array_filter($ids));
  192. $has = ProductClass::getByCondition(['sjId' => $sjId, 'itemId' => ['in', $ids]]);
  193. if (!empty($has)) {
  194. util::fail("有花材已经添加过了");
  195. }
  196. $connection = Yii::$app->db;//事务处理
  197. $transaction = $connection->beginTransaction();
  198. try {
  199. foreach ($data as $v) {
  200. $v['adminId'] = $this->adminId;
  201. $v['sjId'] = $sjId;
  202. ItemService::addGhsItem($v);
  203. }
  204. $transaction->commit();
  205. util::complete('添加成功');
  206. } catch (Exception $e) {
  207. $transaction->rollBack();
  208. util::fail();
  209. }
  210. }
  211. public function actionDelete()
  212. {
  213. util::fail('不能删除哦!');
  214. }
  215. //获取平台里的花材信息
  216. public function actionPlatformItem()
  217. {
  218. $py = Yii::$app->request->get('py', '');
  219. $where = [];
  220. if ($py) {
  221. $where = ['py' => $py];
  222. }
  223. $list = PtItemClass::getItemList($where);
  224. util::success($list);
  225. }
  226. //列出需要进行颜色管理的花材 ssh 20220820
  227. public function actionColorList()
  228. {
  229. $mainId = $this->mainId ?? 0;
  230. $list = ItemClass::getAllByCondition(['mainId' => $mainId, 'variety' => 1], null, '*');
  231. util::success(['list' => $list]);
  232. }
  233. //多颜色管理启用与停用 ssh 20221229
  234. public function actionChangeVariety()
  235. {
  236. $get = Yii::$app->request->get();
  237. $id = $get['id'] ?? 0;
  238. $variety = $get['variety'] ?? 0;
  239. $info = ItemClass::getById($id, true);
  240. if (empty($info) || $info->mainId != $this->mainId) {
  241. util::fail('操作失败');
  242. }
  243. $info->variety = $variety;
  244. $info->save();
  245. util::complete('操作成功');
  246. }
  247. //拆散花材 ssh 20221229
  248. public function actionBreakItem()
  249. {
  250. util::fail('开发中');
  251. util::complete();
  252. }
  253. }