ItemController.php 33 KB

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