ItemController.php 31 KB

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