ItemController.php 28 KB

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