ItemController.php 35 KB

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