ItemController.php 28 KB

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