ItemController.php 32 KB

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