ItemController.php 35 KB

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