ItemController.php 33 KB

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