ItemController.php 28 KB

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