ItemController.php 28 KB

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