ItemController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\item\classes\PtItemClass;
  4. use biz\product\models\Product;
  5. use bizGhs\custom\classes\CustomClass;
  6. use bizGhs\item\classes\ItemClass;
  7. use common\components\dict;
  8. use common\components\imgUtil;
  9. use common\components\miniUtil;
  10. use common\components\noticeUtil;
  11. use common\components\stringUtil;
  12. use common\components\util;
  13. use bizGhs\product\classes\ProductClass;
  14. use bizHd\wx\classes\WxOpenClass;
  15. use Yii;
  16. class ItemController extends BaseController
  17. {
  18. //列出所有花材 ssh 20240222
  19. public function actionGetItemList()
  20. {
  21. $search = Yii::$app->request->get('search', '');
  22. $requestType = Yii::$app->request->get('requestType', 'common');
  23. $status = Yii::$app->request->get('status', 1);
  24. $delStatus = Yii::$app->request->get('delStatus', 0);
  25. $classId = Yii::$app->request->get('classId', 0);
  26. $where['mainId'] = $this->mainId;
  27. $where['delStatus'] = $delStatus;
  28. if (!empty($status)) {
  29. $where['status'] = $status;
  30. }
  31. if ($requestType == 'book') {
  32. unset($where['status']);
  33. }
  34. if (!empty($search)) {
  35. if (stringUtil::isLetter($search)) {
  36. $search = strtolower($search);
  37. $where['py'] = ['like', $search];
  38. } else {
  39. $where['name'] = ['like', $search];
  40. }
  41. } else {
  42. if (!empty($classId)) {
  43. if ($classId == -1) {
  44. $where['discountPrice>'] = 0;
  45. } elseif ($classId == -2) {
  46. $where['reachNum>'] = 0;
  47. } elseif ($classId == -3) {
  48. $where['presell'] = 1;
  49. } else {
  50. $where['classId'] = $classId;
  51. }
  52. }
  53. }
  54. //改价和全部有库存花材列表
  55. if ($requestType == 'changePrice' || $requestType == 'hasStockList') {
  56. $where['stock>'] = 0;
  57. }
  58. $customId = Yii::$app->request->get('customId', 0);
  59. $level = 1;
  60. if (!empty($customId)) {
  61. $custom = CustomClass::getById($customId, true);
  62. $level = $custom->level ?? 1;
  63. }
  64. $itemInfoData = [];
  65. if ($requestType == 'hasStockList') {
  66. //有库存的花材列表
  67. $field = 'id,py,name,classId,itemId,price,skPrice,hjPrice,stock';
  68. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  69. } elseif ($requestType == 'changePrice') {
  70. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,hjPrice,discountPrice,hjDiscountPrice,skDiscountPrice,skMore,hjAddPrice,addPrice,variety,price,hjPrice,stock,onStock,presell,frontHide,reachNum,reachNumDiscount';
  71. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  72. $itemInfoData = ProductClass::changePriceGroup($itemInfoData, $level);
  73. } elseif ($requestType == 'changeStock') {
  74. //修改库存列表
  75. $field = 'id,py,cover,name,cost,itemId,status,classId,addPrice,skPrice,discountPrice,skMore,variety,price,stock,frontHide';
  76. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  77. $itemInfoData = ProductClass::changeStockGroup($itemInfoData, $level);
  78. } elseif ($requestType == 'kd') {
  79. //开单的花材列表
  80. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,hjDiscountPrice,skDiscountPrice,discountPrice,stock,weight,stockWarning,presell,ratioType,smallUnit,smallRatio,bigUnit,ratio,frontHide,reachNum,reachNumDiscount';
  81. $result = ProductClass::getList($field, $where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC]);
  82. $list = $result['list'] ?? [];
  83. $list = ProductClass::kdItemGroup($list, $level);
  84. $result['list'] = $list;
  85. util::success($result);
  86. } elseif ($requestType == 'book') {
  87. //预订花材列表
  88. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,hjDiscountPrice,skDiscountPrice,discountPrice,stock,weight,stockWarning,presell,ratioType,smallUnit,smallRatio,bigUnit,ratio,frontHide';
  89. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  90. $itemInfoData = ProductClass::bookItemGroup($itemInfoData, $level);
  91. } elseif ($requestType == 'itemList') {
  92. //花材列表
  93. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,discountPrice,hjDiscountPrice,skDiscountPrice,stock,onStock,actualSold,status,ratio,ratioType,presell,frontHide,auth,reachNum,reachNumDiscount';
  94. $result = ProductClass::getList($field, $where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC]);
  95. $list = $result['list'] ?? [];
  96. $list = ProductClass::itemListGroup($list, $level);
  97. $result['list'] = $list;
  98. util::success($result);
  99. } elseif ($requestType == 'outList') {
  100. //下架花材列表
  101. $where['status'] = 2;
  102. $where['delStatus'] = 0;
  103. $where['removeStatus'] = 0;
  104. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
  105. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  106. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  107. } elseif ($requestType == 'stopList') {
  108. //停用花材列表
  109. unset($where['status']);
  110. $where['delStatus'] = 1;
  111. $where['removeStatus'] = 0;
  112. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
  113. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  114. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  115. } elseif ($requestType == 'removeList') {
  116. //删除花材列表
  117. unset($where['status']);
  118. $where['delStatus'] = 1;
  119. $where['removeStatus'] = 1;
  120. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
  121. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  122. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  123. } elseif ($requestType == 'check') {
  124. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,frontHide';
  125. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  126. $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
  127. } elseif ($requestType == 'break') {
  128. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,frontHide';
  129. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  130. $itemInfoData = ProductClass::breakItemGroup($itemInfoData, $level);
  131. } elseif ($requestType == 'part') {
  132. //拆散花材
  133. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  134. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  135. $itemInfoData = ProductClass::partItemGroup($itemInfoData, $level);
  136. } elseif ($requestType == 'stockOut') {
  137. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,smallRatio,frontHide';
  138. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  139. $itemInfoData = ProductClass::stockOutGroup($itemInfoData, $level);
  140. } elseif ($requestType == 'cg') {
  141. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,presell,ratioType,smallUnit,bigUnit,ratio,weight,frontHide';
  142. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  143. $itemInfoData = ProductClass::cgItemGroup($itemInfoData, $level);
  144. } elseif ($requestType == 'warning') {
  145. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,discountPrice,stock,onStock,actualSold,presell,bigUnit,stockWarning,status,frontHide';
  146. $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  147. ->andWhere('`stock`+`onStock`<`stockWarning`')
  148. ->andWhere("delStatus=0")
  149. ->select($field)->asArray()->all();
  150. $itemInfoData = ProductClass::warningGroup($itemInfoData, $level);
  151. } else {
  152. util::fail('没有数据');
  153. }
  154. util::success(['list' => $itemInfoData]);
  155. }
  156. //花材申请平台认证 ssh 20231125
  157. public function actionApplyAuth()
  158. {
  159. $get = Yii::$app->request->get();
  160. $id = $get['id'] ?? 0;
  161. $info = ItemClass::getById($id, true);
  162. if (empty($info)) {
  163. util::fail('没有找到花材');
  164. }
  165. if ($info->mainId != $this->mainId) {
  166. util::fail('不是你的花材哦');
  167. }
  168. $shop = $this->shop;
  169. $sjName = $shop->merchantName ?? '';
  170. $shopName = $shop->shopName ?? '';
  171. $name = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  172. $ptItemId = $info->itemId ?? 0;
  173. $ptItem = PtItemClass::getById($ptItemId, true);
  174. if (empty($ptItem)) {
  175. util::fail('没有找到平台花材');
  176. }
  177. $ptItemName = $ptItem->name ?? '';
  178. noticeUtil::push($name . " 申请将【{$ptItemName}/{$ptItemId}】进行认证", '15280215347');
  179. util::complete();
  180. }
  181. //简单花材的列表
  182. public function actionSimpleList()
  183. {
  184. $get = Yii::$app->request->get();
  185. $name = $get['name'] ?? '';
  186. $where = ['mainId' => $this->mainId, 'delStatus' => 0];
  187. if (!empty($name)) {
  188. if (stringUtil::isLetter($name)) {
  189. $where['py'] = ['like', $name];
  190. } else {
  191. $where['name'] = ['like', $name];
  192. }
  193. }
  194. $respond = ItemClass::getSimpleList($where);
  195. util::success($respond);
  196. }
  197. public function actionChangeFrontHide()
  198. {
  199. $get = Yii::$app->request->get();
  200. $id = $get['id'] ?? 0;
  201. $status = $get['status'] ?? '';
  202. if (is_numeric($status) == false) {
  203. util::fail('请选择方式');
  204. }
  205. $info = ItemClass::getById($id, true);
  206. if (empty($info)) {
  207. util::fail('没有找到花材');
  208. }
  209. if ($info->mainId != $this->mainId) {
  210. util::fail('无法操作');
  211. }
  212. $info->frontHide = $status;
  213. $info->save();
  214. util::complete();
  215. }
  216. //检测是否要刷新
  217. public function actionCheckRefresh()
  218. {
  219. $mainId = $this->mainId;
  220. $staffId = $this->shopAdminId;
  221. $respond = Yii::$app->redis->executeCommand('GET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  222. if ($respond == 'yes') {
  223. util::success(['remind' => 1]);
  224. }
  225. util::complete();
  226. }
  227. //批量恢复花材 ssh 20230206
  228. public function actionBatchRecover()
  229. {
  230. $post = Yii::$app->request->post();
  231. $string = $post['ids'] ?? '';
  232. $ids = json_decode($string, true);
  233. $ids = array_unique(array_filter($ids));
  234. if (empty($ids)) {
  235. util::fail('请选择花材');
  236. }
  237. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  238. if (empty($infoList)) {
  239. util::fail('请选择花材哦');
  240. }
  241. foreach ($infoList as $info) {
  242. if ($info->mainId != $this->mainId) {
  243. util::fail('请选择自己的花材');
  244. }
  245. $info->removeStatus = 0;
  246. $info->save();
  247. }
  248. util::complete('操作成功');
  249. }
  250. //批量删除花材 ssh 202302026
  251. public function actionBatchRemove()
  252. {
  253. $post = Yii::$app->request->post();
  254. $string = $post['ids'] ?? '';
  255. $ids = json_decode($string, true);
  256. $ids = array_unique(array_filter($ids));
  257. if (empty($ids)) {
  258. util::fail('请选择花材');
  259. }
  260. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  261. if (empty($infoList)) {
  262. util::fail('请选择花材哦');
  263. }
  264. foreach ($infoList as $info) {
  265. if ($info->mainId != $this->mainId) {
  266. util::fail('请选择自己的花材');
  267. }
  268. $name = $info->name ?? '';
  269. if ($info->delStatus != 1) {
  270. util::fail($name . ' 停用了才能删除');
  271. }
  272. $info->removeStatus = 1;
  273. $info->save();
  274. }
  275. util::complete('操作成功');
  276. }
  277. //批量启用花材 ssh 20230206
  278. public function actionBatchEnable()
  279. {
  280. $post = Yii::$app->request->post();
  281. $string = $post['ids'] ?? '';
  282. $ids = json_decode($string, true);
  283. $ids = array_unique(array_filter($ids));
  284. if (empty($ids)) {
  285. util::fail('请选择花材');
  286. }
  287. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  288. if (empty($infoList)) {
  289. util::fail('请选择花材哦');
  290. }
  291. foreach ($infoList as $info) {
  292. if ($info->mainId != $this->mainId) {
  293. util::fail('请选择自己的花材');
  294. }
  295. $info->delStatus = 0;
  296. $info->save();
  297. }
  298. util::complete('操作成功');
  299. }
  300. //批量停用花材 20230206
  301. public function actionBatchStop()
  302. {
  303. $post = Yii::$app->request->post();
  304. $string = $post['ids'] ?? '';
  305. $ids = json_decode($string, true);
  306. $ids = array_unique(array_filter($ids));
  307. if (empty($ids)) {
  308. util::fail('请选择花材');
  309. }
  310. $infoList = ItemClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,mainId,status,delStatus,removeStatus', null, true);
  311. if (empty($infoList)) {
  312. util::fail('请选择花材哦');
  313. }
  314. foreach ($infoList as $info) {
  315. if ($info->mainId != $this->mainId) {
  316. util::fail('请选择自己的花材');
  317. }
  318. $name = $info->name ?? '';
  319. if ($info->status != 2) {
  320. util::fail($name . ' 下载了才能停用');
  321. }
  322. $info->delStatus = 1;
  323. $info->save();
  324. }
  325. util::complete('操作成功');
  326. }
  327. //获取给散客下单的花材海报 ssh 20220111
  328. public function actionGetSkPoster()
  329. {
  330. $get = Yii::$app->request->get();
  331. $id = $get['id'] ?? 0;
  332. $item = ItemClass::getById($id, true);
  333. if (empty($item) || $item->mainId != $this->mainId) {
  334. util::fail('获取失败');
  335. }
  336. $cover = $item->cover ?? '';
  337. if (empty($cover)) {
  338. util::fail('获取失败');
  339. }
  340. $merchant = WxOpenClass::getMallWxInfo();
  341. $page = 'pages/item/detail';
  342. $ptStyle = dict::getDict('ptStyle', 'mall');
  343. $shop = $this->shop;
  344. $lsShopId = $shop->lsShopId ?? 0;
  345. //scene不能超过32个字条
  346. $scene = "id=" . $id . '&a=' . $lsShopId;
  347. $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  348. $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
  349. $miniCodeBase64 = stringUtil::ossBase64($miniCode);
  350. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
  351. $prefix = imgUtil::getPrefix();
  352. $price = $item->skPrice ?? 0;
  353. if ($item->discountPrice > 0) {
  354. $skMore = $item->skMore ?? 0;
  355. $price = bcadd($item->discountPrice, $skMore, 2);
  356. }
  357. $newPrice = '¥' . floatval($price);
  358. $priceBase64 = stringUtil::ossBase64($newPrice);
  359. $name = $item->name ?? '';
  360. $nameBase64 = stringUtil::ossBase64($name);
  361. $staff = $this->shopAdmin;
  362. $staffName = $staff->name ?? '';
  363. $newStaffName = $staffName . ' 为您推荐';
  364. $staffNameBase64 = stringUtil::ossBase64($newStaffName);
  365. //花材主图
  366. $itemCover = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
  367. $itemCoverBase64 = stringUtil::ossBase64($itemCover);
  368. $logoBase64 = '';
  369. if (in_array($this->mainId, [52, 1459, 13495])) {
  370. $logo = 'poster/hyxh_ncd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  371. if ($this->mainId == 1459) {
  372. $logo = 'poster/hyxh_gcd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  373. }
  374. if ($this->mainId == 13495) {
  375. $logo = 'poster/hyxh_hzd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  376. }
  377. $logoBase64 = stringUtil::ossBase64($logo);
  378. }
  379. $url = $prefix . 'poster/1234.jpg?x-oss-process=image';
  380. //花材主图
  381. $url .= '/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
  382. //小程序码
  383. $url .= '/watermark,image_' . $miniCodeBase64 . ',g_se';
  384. if (!empty($logoBase64)) {
  385. //logo
  386. $url .= '/watermark,image_' . $logoBase64 . ',g_se,x_65,y_65';
  387. }
  388. //为你推荐
  389. $url .= '/watermark,text_' . $staffNameBase64 . ',g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
  390. //标题
  391. $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
  392. //价格
  393. $url .= '/watermark,text_' . $priceBase64 . ',g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
  394. $respond = ['imgUrl' => $url];
  395. util::success($respond);
  396. }
  397. //获取给花店下单的花材海报 ssh 20220111
  398. public function actionGetHdPoster()
  399. {
  400. $get = Yii::$app->request->get();
  401. $id = $get['id'] ?? 0;
  402. $item = ItemClass::getById($id, true);
  403. if (empty($item) || $item->mainId != $this->mainId) {
  404. util::fail('获取失败');
  405. }
  406. $cover = $item->cover ?? '';
  407. if (empty($cover)) {
  408. util::fail('获取失败');
  409. }
  410. $merchant = WxOpenClass::getWxInfo();
  411. $page = 'admin/ghsProduct/detail';
  412. $ptStyle = dict::getDict('ptStyle', 'hd');
  413. //小程序码,scene不能超过32个字条
  414. $scene = "id=" . $id . '&sId=' . $this->shopId;
  415. $miniCode = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
  416. $miniCode = $miniCode . '?x-oss-process=image/resize,m_fill,h_200,w_200';
  417. $miniCodeBase64 = stringUtil::ossBase64($miniCode);
  418. Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  419. $prefix = imgUtil::getPrefix();
  420. $price = $item->price ?? 0;
  421. if ($item->discountPrice > 0) {
  422. $price = $item->discountPrice;
  423. }
  424. $newPrice = '¥' . floatval($price);
  425. $priceBase64 = stringUtil::ossBase64($newPrice);
  426. $name = $item->name ?? '';
  427. $nameBase64 = stringUtil::ossBase64($name);
  428. $staff = $this->shopAdmin;
  429. $staffName = $staff->name ?? '';
  430. $newStaffName = $staffName . ' 为您推荐';
  431. $staffNameBase64 = stringUtil::ossBase64($newStaffName);
  432. //花材主图
  433. $itemCover = $cover . '?x-oss-process=image/resize,m_fill,h_750,w_750';
  434. $itemCoverBase64 = stringUtil::ossBase64($itemCover);
  435. $logoBase64 = '';
  436. if (in_array($this->mainId, [52, 1459, 13495])) {
  437. $logo = 'poster/hyxh_ncd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  438. if ($this->mainId == 1459) {
  439. $logo = 'poster/hyxh_gcd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  440. }
  441. if ($this->mainId == 13495) {
  442. $logo = 'poster/hyxh_hzd_logo.png?x-oss-process=image/resize,m_fill,h_90,w_90';
  443. }
  444. $logoBase64 = stringUtil::ossBase64($logo);
  445. }
  446. $url = $prefix . 'poster/1234.jpg?x-oss-process=image';
  447. //花材主图
  448. $url .= '/watermark,image_' . $itemCoverBase64 . ',g_nw,x_0,y_0';
  449. //小程序码
  450. $url .= '/watermark,image_' . $miniCodeBase64 . ',g_se';
  451. if (!empty($logoBase64)) {
  452. //logo
  453. $url .= '/watermark,image_' . $logoBase64 . ',g_se,x_65,y_65';
  454. }
  455. //为你推荐
  456. $url .= '/watermark,text_' . $staffNameBase64 . ',g_sw,x_18,y_235,color_8B8989,type_d3F5LW1pY3JvaGVp,size_30';
  457. //标题
  458. $url .= '/watermark,text_' . $nameBase64 . ',g_sw,x_18,y_145';
  459. //价格
  460. $url .= '/watermark,text_' . $priceBase64 . ',g_sw,x_18,y_50,color_EE2C2C,type_d3F5LW1pY3JvaGVp,size_50';
  461. $respond = ['imgUrl' => $url];
  462. util::success($respond);
  463. }
  464. //是否有C级价格大于B级的 ssh 20221204
  465. public function actionGetErrorPrice()
  466. {
  467. $shop = $this->shop;
  468. $list = ItemClass::errorPrice($shop);
  469. util::success(['list' => $list]);
  470. }
  471. //列出所有花材,包括特价花材列表 ssh 20220315
  472. public function actionShowList()
  473. {
  474. $get = Yii::$app->request->get();
  475. $customId = $get['customId'] ?? 0;
  476. $custom = CustomClass::getById($customId, true);
  477. $where['mainId'] = $this->mainId;
  478. $where['delStatus'] = 0;
  479. $where['status'] = 1;
  480. $list = ItemClass::getShowList($where, $custom);
  481. $mainId = $this->mainId;
  482. $get = Yii::$app->request->get();
  483. $isCashier = $get['isCashier'] ?? 0;
  484. if ($isCashier == 1) {
  485. //去掉收银台提示价格更新
  486. $staffId = $this->shopAdminId;
  487. Yii::$app->redis->executeCommand('DEL', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh']);
  488. }
  489. util::success(['list' => $list]);
  490. }
  491. public function actionAdd()
  492. {
  493. util::fail('开发中');
  494. }
  495. //批量添加花材
  496. public function actionBatchAdd()
  497. {
  498. $shopAdmin = $this->shopAdmin;
  499. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  500. util::fail('超管才能操作');
  501. }
  502. $post = Yii::$app->request->post();
  503. //[{"itemId":"1175","classId":"3548","price":"5","skPrice":"8","cost":"1","name":"卡娜百合"}]
  504. $data = $post['data'];
  505. if (empty($data)) {
  506. util::fail("请选花材");
  507. }
  508. $data = json_decode($data, true);
  509. if (is_array($data) == false || empty($data)) {
  510. util::fail("请选花材");
  511. }
  512. $shop = $this->shop;
  513. $shopId = $this->shopId;
  514. $mainId = $this->mainId;
  515. $sjId = $this->sjId;
  516. $adminId = $this->adminId;
  517. $ids = array_column($data, 'itemId');
  518. $ids = array_unique(array_filter($ids));
  519. $has = ProductClass::getByCondition(['mainId' => $mainId, 'itemId' => ['in', $ids]]);
  520. if (!empty($has)) {
  521. $hasName = $has->name ?? '';
  522. util::fail($hasName . " 已经添加过了");
  523. }
  524. $ptItemInfo = PtItemClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
  525. $connection = Yii::$app->db;
  526. $transaction = $connection->beginTransaction();
  527. try {
  528. foreach ($data as $v) {
  529. $ptItemId = $v['itemId'] ?? 0;
  530. $ratio = $ptItemInfo[$ptItemId]['ratio'] ?? 20;
  531. $shelfLife = $ptItemInfo[$ptItemId]['shelfLife'] ?? 7;
  532. $ratioType = $ptItemInfo[$ptItemId]['ratioType'] ?? 0;
  533. $variety = $ptItemInfo[$ptItemId]['variety'] ?? 0;
  534. $stockWarning = $ptItemInfo[$ptItemId]['stockWarning'] ?? 5;
  535. $weight = $ptItemInfo[$ptItemId]['weight'] ?? 1;
  536. $bigUnit = $ptItemInfo[$ptItemId]['bigUnit'] ?? '扎';
  537. $smallUnit = $ptItemInfo[$ptItemId]['smallUnit'] ?? '支';
  538. $bigUnitId = $ptItemInfo[$ptItemId]['bigUnitId'] ?? 1;
  539. $smallUnitId = $ptItemInfo[$ptItemId]['smallUnitId'] ?? 2;
  540. $cover = $ptItemInfo[$ptItemId]['cover'] ?? 'default-img.png';
  541. $v['ratio'] = $ratio;
  542. $v['cover'] = $cover;
  543. $v['shelfLife'] = $shelfLife;
  544. $v['ratioType'] = $ratioType;
  545. $v['variety'] = $variety;
  546. $v['stockWarning'] = $stockWarning;
  547. $v['weight'] = $weight;
  548. $v['bigUnit'] = $bigUnit;
  549. $v['smallUnit'] = $smallUnit;
  550. $v['bigUnitId'] = $bigUnitId;
  551. $v['smallUnitId'] = $smallUnitId;
  552. $v['adminId'] = $adminId;
  553. $v['sjId'] = $sjId;
  554. $v['shopId'] = $shopId;
  555. $v['mainId'] = $mainId;
  556. $v['staffName'] = $shopAdmin->name ?? '';
  557. $name = $v['name'] ?? '';
  558. $price = is_numeric($v['price']) ? $v['price'] : 0;
  559. $skPrice = is_numeric($v['skPrice']) ? $v['skPrice'] : 0;
  560. $cost = is_numeric($v['cost']) ? $v['cost'] : 0;
  561. if ($price <= 0) {
  562. util::fail("请填写{$name}的批发价");
  563. }
  564. if ($skPrice <= 0) {
  565. util::fail("请填写{$name}的零售价");
  566. }
  567. if ($cost <= 0) {
  568. util::fail("请填写{$name}的成本价");
  569. }
  570. if ($price > $skPrice) {
  571. util::fail("{$name}的批发价比零售价还高");
  572. }
  573. if ($cost > $price) {
  574. util::fail("{$name}的成本价比批发价还高");
  575. }
  576. $skMore = bcsub($skPrice, $price, 2);
  577. $addPrice = bcsub($price, $cost, 2);
  578. $v['skMore'] = $skMore;
  579. $v['addPrice'] = $addPrice;
  580. $v['hjAddPrice'] = $addPrice;
  581. $v['hjPrice'] = $price;
  582. ProductClass::addProduct($v, $shop);
  583. }
  584. $transaction->commit();
  585. util::complete('添加成功');
  586. } catch (Exception $e) {
  587. $transaction->rollBack();
  588. util::fail();
  589. }
  590. }
  591. public function actionDelete()
  592. {
  593. util::fail('不能删除哦!');
  594. }
  595. //获取平台里的花材信息
  596. public function actionPlatformItem()
  597. {
  598. $py = Yii::$app->request->get('py', '');
  599. $where = [];
  600. if ($py) {
  601. $where = ['py' => $py];
  602. }
  603. $list = PtItemClass::getItemList($where);
  604. util::success($list);
  605. }
  606. //列出需要进行颜色管理的花材 ssh 20220820
  607. public function actionColorList()
  608. {
  609. $mainId = $this->mainId ?? 0;
  610. $list = ItemClass::getAllByCondition(['mainId' => $mainId, 'variety' => 1], null, '*');
  611. util::success(['list' => $list]);
  612. }
  613. //多颜色管理启用与停用 ssh 20221229
  614. public function actionChangeVariety()
  615. {
  616. $get = Yii::$app->request->get();
  617. $id = $get['id'] ?? 0;
  618. $variety = $get['variety'] ?? 0;
  619. $info = ItemClass::getById($id, true);
  620. if (empty($info) || $info->mainId != $this->mainId) {
  621. util::fail('操作失败');
  622. }
  623. $info->variety = $variety;
  624. $info->save();
  625. util::complete('操作成功');
  626. }
  627. //拆散花材 ssh 20221229
  628. public function actionBreakItem()
  629. {
  630. util::fail('开发中');
  631. util::complete();
  632. }
  633. }