ItemController.php 32 KB

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