ItemController.php 13 KB

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