ItemController.php 11 KB

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