ItemController.php 32 KB

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