ItemController.php 33 KB

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