ProductController.php 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  1. <?php
  2. namespace hd\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use biz\item\classes\PtItemClass;
  5. use biz\shop\classes\ShopClass;
  6. use biz\shop\classes\ShopExtClass;
  7. use bizGhs\item\classes\ItemClassClass;
  8. use bizGhs\product\classes\ProductClass;
  9. use bizGhs\product\services\ProductService;
  10. use bizHd\admin\classes\ShopAdminClass;
  11. use bizHd\item\classes\UnitChangeClass;
  12. use bizHd\purchase\classes\PurchaseClass;
  13. use bizHd\purchase\classes\PurchaseItemClass;
  14. use bizHd\pictext\classes\PicTextGhsItemClass;
  15. use common\components\printUtil;
  16. use common\components\stringUtil;
  17. use common\components\util;
  18. use Yii;
  19. use yii\helpers\ArrayHelper;
  20. class ProductController extends BaseController
  21. {
  22. public $guestAccess = ['ghs-item', 'ghs-product-detail'];
  23. //复制新建花材 ssh 20250523
  24. public function actionClone()
  25. {
  26. $post = Yii::$app->request->post();
  27. $appVersion = $post['appVersion'] ?? 0;
  28. if ($appVersion != 1) {
  29. util::fail('请先升级应用');
  30. }
  31. $discountPrice = $post['discountPrice'] ?? 0;
  32. if ($discountPrice > 0) {
  33. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  34. $addPrice = $post['addPrice'] ?? 0;
  35. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  36. $skMore = $post['skMore'] ?? 0;
  37. $diff = bcsub($addPrice, $hjAddPrice, 2);
  38. if ($diff > 0 && $discountPrice > $diff) {
  39. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  40. } else {
  41. $hjDiscountPrice = $discountPrice;
  42. }
  43. $diff = bcsub($skMore, $addPrice, 2);
  44. if ($diff > 0) {
  45. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  46. } else {
  47. $skDiscountPrice = $discountPrice;
  48. }
  49. $post['skDiscountPrice'] = $skDiscountPrice;
  50. $post['hjDiscountPrice'] = $hjDiscountPrice;
  51. }
  52. }
  53. $shop = $this->shop;
  54. $join = $shop->join ?? 0;
  55. $default = $shop->default ?? 0;
  56. if ($join == 0 && $default == 0) {
  57. util::fail('请在首店操作');
  58. }
  59. $shopAdmin = $this->shopAdmin;
  60. if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
  61. util::fail('管理员才能添加花材');
  62. }
  63. $post['sjId'] = $this->sjId;
  64. $post['adminId'] = $this->adminId;
  65. $post['mainId'] = $this->mainId;
  66. $post['staffName'] = $shopAdmin->name ?? '';
  67. $price = $post['price'] ?? 0;
  68. if (empty($price) || $price <= 0) {
  69. util::fail('请填写批发价');
  70. }
  71. $skPrice = $post['skPrice'] ?? 0;
  72. if (empty($skPrice) || $skPrice <= 0) {
  73. util::fail('请填写零售价');
  74. }
  75. $hjPrice = $post['hjPrice'] ?? 0;
  76. if (empty($hjPrice) || $hjPrice <= 0) {
  77. util::fail('请填写会员价');
  78. }
  79. $addPrice = $post['addPrice'] ?? 0;
  80. if ($addPrice > $price) {
  81. util::fail('批发价的加价不能大于售价');
  82. }
  83. // 图片列表数组转换为字符串
  84. if (is_array($post['images'])) {
  85. $post['images'] = implode(',', $post['images']);
  86. }
  87. //复制标识
  88. $post['copy'] = 1;
  89. //去除无用的字段
  90. unset($post['viewNum']);
  91. unset($post['actualSold']);
  92. unset($post['itemId']);
  93. unset($post['id']);
  94. unset($post['delStatus']);
  95. ProductClass::addProduct($post, $this->shop);
  96. util::complete('复制成功');
  97. }
  98. //花材展示状态控制 ssh 20250519
  99. public function actionDelStatusUpdate()
  100. {
  101. $post = Yii::$app->request->post();
  102. $shop = $this->shop;
  103. $join = $shop->join ?? 0;
  104. $default = $shop->default ?? 0;
  105. if ($join == 0 && $default == 0) {
  106. util::fail('请在首店操作');
  107. }
  108. $id = $post['id'] ?? 0;
  109. $delStatus = $post['delStatus'] ?? 0;
  110. $product = ProductClass::getById($id, true);
  111. if ($product->mainId != $this->mainId) {
  112. util::fail('不是你的花材哦!!');
  113. }
  114. //扫码收款、直接收款和特价商品,不可删除,多处要同步修改 system_item
  115. if (getenv('YII_ENV') == 'production') {
  116. $systemItem = [78076, 80960, 81004];
  117. $adminList = [4, 1960];
  118. } else {
  119. $systemItem = [11157, 11156, 11158];
  120. $adminList = [919, 932];
  121. }
  122. if (in_array($product->itemId, $systemItem)) {
  123. $adminId = $this->adminId;
  124. if (!in_array($adminId, $adminList)) {
  125. util::fail('系统花材,不可删除');
  126. }
  127. }
  128. $product->delStatus = $delStatus;
  129. if ($delStatus == 1) {
  130. $product->stock = 0;
  131. $product->status = 2;
  132. }
  133. $product->save();
  134. $ptItemId = $product->itemId ?? 0;
  135. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  136. //总店修改同步到所有门店
  137. $sjId = $shop->sjId ?? 0;
  138. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  139. foreach ($chainShopList as $chainShop) {
  140. $chainShopId = $chainShop->id ?? 0;
  141. if (isset($chainShop->join) && $chainShop->join == 1) {
  142. continue;
  143. }
  144. if ($chainShopId == $shop->id) {
  145. continue;
  146. }
  147. $chainMainId = $chainShop->mainId ?? 0;
  148. $chainProduct = ProductClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
  149. if (!empty($chainProduct)) {
  150. $chainProduct->delStatus = $delStatus;
  151. if ($delStatus == 1) {
  152. $chainProduct->stock = 0;
  153. $chainProduct->status = 2;
  154. }
  155. $chainProduct->save();
  156. }
  157. }
  158. }
  159. util::complete();
  160. }
  161. //打印花材的标签 ssh 20220602
  162. public function actionPrint()
  163. {
  164. $get = Yii::$app->request->get();
  165. $id = $get['id'] ?? 0;
  166. $num = $get['num'] ?? 1;
  167. $num = floatval($num);
  168. $num = (int)$num;
  169. $type = $get['type'] ?? 0;
  170. $priceOption = $get['priceOption'] ?? 0;
  171. $info = ProductClass::getById($id, true);
  172. if (empty($info)) {
  173. util::fail('没有找到花材');
  174. }
  175. $name = $info->name ?? '';
  176. $ptItemId = $info->itemId ?? 0;
  177. $mainId = $info->mainId ?? 0;
  178. $shopId = $this->shopId;
  179. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  180. if (empty($ext)) {
  181. util::fail('没有找到门店信息');
  182. }
  183. $printLabelSn = $ext->printLabelSn ?? '';
  184. if (empty($printLabelSn)) {
  185. util::fail('请设置标签打印机');
  186. }
  187. $p = new printUtil($printLabelSn);
  188. $unit = $info->ratio . $info->smallUnit . '/' . $info->bigUnit;
  189. if (isset($info->ratioType) && $info->ratioType == 1) {
  190. $unit = '若干' . $info->smallUnit . '/' . $info->bigUnit;
  191. }
  192. $p->times = $num;
  193. if ($priceOption == 2) {
  194. // 每7个汉字截取一次(支持汉字、字母、数字混合),多处需要同步修改,关键词 label_print_substr
  195. $content = '';
  196. $len = mb_strlen($name, 'UTF-8');
  197. $baseNum = 30;
  198. $u = 0;
  199. for ($i = 0; $i < $len; $i += 6) {
  200. $currentName = mb_substr($name, $i, 6, 'UTF-8');
  201. $number = $baseNum + 90 * $u;
  202. $u++;
  203. $content .= '<TEXT x="10" y="' . $number . '" font="12" w="3" h="3" r="0">' . $currentName . '</TEXT>';
  204. }
  205. } else {
  206. if (stringUtil::getWordNum($name) > 8) {
  207. $content = '<TEXT x="30" y="30" font="12" w="1" h="1" r="0">' . $name . '</TEXT>';
  208. } else {
  209. $content = '<TEXT x="30" y="30" font="12" w="2" h="2" r="0">' . $name . '</TEXT>';
  210. }
  211. }
  212. if ($type == 0) {
  213. if ($priceOption != 2) {
  214. //打标签
  215. $content .= '<BC128 x="30" y="115" h="75" s="1" r="0" n="3" w="10">' . $ptItemId . '</BC128>';
  216. if (in_array($mainId, [52, 1459])) {
  217. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">惠雅鲜花</TEXT>';
  218. } elseif ($mainId == 16948) {
  219. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">淘花里鲜花</TEXT>';
  220. } elseif ($mainId == 72057) {
  221. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">淘花里小榄店</TEXT>';
  222. } else {
  223. $content .= '<TEXT x="30" y="250" font="12" w="1" h="1" r="0">' . $unit . '</TEXT>';
  224. }
  225. }
  226. } else {
  227. if (getenv('YII_ENV') == 'production') {
  228. $doublePrice = [52, 1459];
  229. } else {
  230. $doublePrice = [];
  231. }
  232. if (in_array($this->mainId, $doublePrice)) {
  233. //打价格,显示正价和会员价
  234. $price = $info->skPrice ?? 0;
  235. $price = floatval($price);
  236. $hyPrice = $info->price ?? 0;
  237. $hyPrice = floatval($hyPrice);
  238. $content .= '<TEXT x="35" y="90" font="12" w="2" h="2" r="0">----------</TEXT>';
  239. $content .= '<TEXT x="35" y="150" font="12" w="2" h="2" r="0">正价 ' . $price . '元</TEXT>';
  240. $content .= '<TEXT x="35" y="230" font="12" w="2" h="2" r="0">会员价 ' . $hyPrice . '元</TEXT>';
  241. } else {
  242. //打价格,显示零售价,并且不带元,杭州斗南鲜花不要带元
  243. $price = $info->skPrice ?? 0;
  244. $price = floatval($price);
  245. $content .= '<TEXT x="35" y="150" font="12" w="4" h="4" r="0">' . $price . '</TEXT>';
  246. }
  247. }
  248. $p->printLabelMsg($content);
  249. util::complete();
  250. }
  251. //新增花材 20250523 ssh
  252. public function actionAdd()
  253. {
  254. $post = Yii::$app->request->post();
  255. $discountPrice = $post['discountPrice'] ?? 0;
  256. if ($discountPrice > 0) {
  257. if (empty($post['hjDiscountPrice'])) {
  258. $addPrice = $post['addPrice'] ?? 0;
  259. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  260. $skMore = $post['skMore'] ?? 0;
  261. $diff = bcsub($addPrice, $hjAddPrice, 2);
  262. if ($diff > 0 && $discountPrice > $diff) {
  263. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  264. } else {
  265. $hjDiscountPrice = $discountPrice;
  266. }
  267. $diff = bcsub($skMore, $addPrice, 2);
  268. if ($diff > 0) {
  269. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  270. } else {
  271. $skDiscountPrice = $discountPrice;
  272. }
  273. $post['skDiscountPrice'] = $skDiscountPrice;
  274. $post['hjDiscountPrice'] = $hjDiscountPrice;
  275. }
  276. }
  277. $shop = $this->shop;
  278. $join = $shop->join ?? 0;
  279. $default = $shop->default ?? 0;
  280. if ($join == 0 && $default == 0) {
  281. util::fail('当前直营分店,请切回总店添加花材');
  282. }
  283. $shopAdmin = $this->shopAdmin;
  284. if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
  285. util::fail('管理员才能添加花材');
  286. }
  287. $post['sjId'] = $this->sjId;
  288. $post['adminId'] = $this->adminId;
  289. $post['mainId'] = $this->mainId;
  290. $price = $post['price'] ?? 0;
  291. $addPrice = $post['addPrice'] ?? 0;
  292. if ($addPrice > $price) {
  293. util::fail('加价不能大于售价');
  294. }
  295. $weight = isset($post['weight']) && is_numeric($post['weight']) ? $post['weight'] : 0;
  296. if ($weight <= 0) {
  297. util::fail('请填写重量,最小0.1');
  298. }
  299. $post['staffName'] = $shopAdmin->name ?? '';
  300. // 图片列表数组转换为字符串
  301. if (is_array($post['images'])) {
  302. $post['images'] = implode(',', $post['images']);
  303. }
  304. ProductClass::addProduct($post, $this->shop);
  305. util::complete('添加成功');
  306. }
  307. //获取拼音缩写 ssh 20210707
  308. public function actionPy()
  309. {
  310. $name = Yii::$app->request->get('name');
  311. $py = stringUtil::py($name);
  312. util::success(['py' => $py]);
  313. }
  314. //所有花材
  315. public function actionAll()
  316. {
  317. $where = [];
  318. $where['mainId'] = $this->mainId;
  319. $classId = Yii::$app->request->get('classId', 0);
  320. if (!empty($classId)) {
  321. $where['classId'] = $classId;
  322. }
  323. $status = Yii::$app->request->get('status', 0);
  324. if (!empty($status)) {
  325. $where['status'] = $status;
  326. }
  327. $delStatus = Yii::$app->request->get('delStatus', 0);
  328. if ($delStatus != 2) {
  329. $where['delStatus'] = $delStatus;
  330. }
  331. //零售价
  332. $level = 0;
  333. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  334. $data = ProductClass::groupProductInfo($data, $level);
  335. util::success(['list' => $data]);
  336. }
  337. public function actionIndex()
  338. {
  339. $py = Yii::$app->request->get('py', '');
  340. //默认显示上架商品
  341. $status = Yii::$app->request->get('status', 1);
  342. //默认显示未删除商品
  343. $delStatus = Yii::$app->request->get('delStatus', 0);
  344. //获取所有当前供货商的分类 (全部、常用)
  345. //根据分类组装分类下的花材信息
  346. //中央ID
  347. $classIds = ItemClassClass::getGhsItemClassAll($this->mainId);
  348. $where['mainId'] = $this->mainId;
  349. if ($py) {
  350. $pyName = strtolower($py);
  351. $where['py'] = $pyName;
  352. }
  353. if (!empty($status)) {
  354. $where['status'] = $status;
  355. }
  356. $where['delStatus'] = $delStatus;
  357. $level = 0;
  358. $field = 'id,cover,name,cost,itemId,classId,property,skPrice,skMore,addPrice,variety,price,discountPrice,skDiscountPrice,stock,stockWarning,presell,ratioType,smallRatio,smallUnit,bigUnit,ratio,actualSold';
  359. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  360. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  361. $respond = ProductService::assembleData($classIds, $itemInfoData, true);
  362. $classItem = $respond['classItem'] ?? [];
  363. util::success($classItem);
  364. }
  365. //当前门店所有花材分类
  366. public function actionList()
  367. {
  368. $classId = Yii::$app->request->get('classId', 0);
  369. $pyName = Yii::$app->request->get('py', '');
  370. if ($pyName) {
  371. $pyName = strtolower($pyName);
  372. $where['py'] = $pyName;
  373. }
  374. $where['mainId'] = $this->mainId;
  375. if (!empty($classId)) {
  376. $where['classId'] = $classId;
  377. }
  378. $type = Yii::$app->request->get('type', '');
  379. $showPage = Yii::$app->request->get('showPage', 0);
  380. //需要显示分页
  381. if ($showPage) {
  382. $respond = ProductClass::getList("*", $where, "inTurn desc");
  383. $respond['list'] = ProductClass::groupClassName($this->mainId, $respond['list']);
  384. $respond['list'] = ProductClass::groupProductInfo($respond['list']);
  385. util::success($respond);
  386. }
  387. $data = ProductClass::getAllByCondition($where, "inTurn desc", "*");
  388. $data = ProductClass::groupProductInfo($data);
  389. if ($type == 'waring') {
  390. //库存预警
  391. $newData = [];
  392. foreach ($data as $v) {
  393. if ($v['stock'] <= $v['stockWarning']) {
  394. $newData[] = $v;
  395. }
  396. }
  397. util::success(['list' => $newData]);
  398. }
  399. util::success(['list' => $data]);
  400. }
  401. //批量修改更多,包括排序、重量和保质期 ssh 20211211
  402. public function actionBatchChangeMore()
  403. {
  404. $shop = $this->shop;
  405. $default = $shop->default ?? 0;
  406. $join = $shop->join ?? 0;
  407. if ($default == 0 && $join == 0) {
  408. util::fail('当前是直营店,请返回总店修改');
  409. }
  410. $shopAdmin = $this->shopAdmin;
  411. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  412. util::fail('超管才能操作');
  413. }
  414. $addData = Yii::$app->request->post('addData', '');
  415. if (empty($addData)) {
  416. util::fail('没有花材');
  417. }
  418. $itemData = json_decode($addData, true);
  419. if (is_array($itemData) == false) {
  420. util::fail('没有花材...');
  421. }
  422. $ids = array_column($itemData, 'id');
  423. $infoList = ProductClass::getByIds($ids, null, 'id');
  424. if (empty($infoList)) {
  425. util::fail('没有花材');
  426. }
  427. foreach ($infoList as $info) {
  428. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  429. util::fail('不是你的花材不能修改');
  430. }
  431. }
  432. //总店修改同步到所有门店
  433. $sjId = $shop->sjId ?? 0;
  434. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  435. foreach ($itemData as $key => $data) {
  436. $id = $data['id'] ?? 0;
  437. unset($data['id']);
  438. ProductClass::updateById($id, $data);
  439. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  440. if (empty($ptItemId)) {
  441. continue;
  442. }
  443. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  444. foreach ($chainShopList as $chainShop) {
  445. $currentMainId = $chainShop->mainId ?? 0;
  446. if ($currentMainId == $shop->mainId) {
  447. //前面已经修改过了,不需要重复修改
  448. continue;
  449. }
  450. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  451. }
  452. }
  453. }
  454. util::complete('修改成功');
  455. }
  456. //批量改价
  457. public function actionBatchChangePrice()
  458. {
  459. $shop = $this->shop ?? [];
  460. $shopId = $shop->id ?? 0;
  461. $default = $shop->default ?? 0;
  462. $join = $shop->join ?? 0;
  463. $shopAdmin = $this->shopAdmin;
  464. $adminId = $this->adminId ?? 0;
  465. //normal常规改价,cg采购改价
  466. $changeType = Yii::$app->request->post('changeType', 'normal');
  467. $doType = Yii::$app->request->post('doType', 0);
  468. if ($changeType == 'cg' && $doType == 0) {
  469. if (getenv('YII_ENV') == 'production') {
  470. //小蔡鲜花的几个分店的零售店不能修改价格
  471. if (in_array($shopId, [29153, 29155, 29157, 29162, 29164])) {
  472. util::fail('本店不能改价哦');
  473. }
  474. } else {
  475. if (in_array($shopId, [36545])) {
  476. util::fail('本店无法改价哈');
  477. }
  478. }
  479. }
  480. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  481. util::fail('超管才能修改');
  482. }
  483. if ($join == 0 && $default == 0) {
  484. //util::fail('当前直营分店,只能回总店修改价格');
  485. }
  486. $targetId = Yii::$app->request->post('targetId', 0);
  487. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  488. $post = Yii::$app->request->post();
  489. $data = $post['data'] ?? '';
  490. if (empty($data)) {
  491. util::fail('没有修改');
  492. }
  493. $arr = json_decode($data, true);
  494. if (empty($arr)) {
  495. util::fail('没有修改!');
  496. }
  497. $connection = Yii::$app->db;
  498. $transaction = $connection->beginTransaction();
  499. try {
  500. if ($doType == 0 || $doType == 1) {
  501. $cg = PurchaseClass::getLockById($targetId);
  502. if (!empty($cg)) {
  503. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  504. util::fail('不是您的采购单');
  505. }
  506. if ($cg->status == PurchaseClass::STATUS_UN_SEND && $cg->book == 1) {
  507. util::fail('预订单只有发货后,才能确认收货');
  508. }
  509. //没有发货则先发货
  510. if ($cg->status == PurchaseClass::STATUS_UN_SEND) {
  511. $cg = PurchaseClass::orderSend($cg, [], true);
  512. }
  513. //确认收货并入库
  514. if ($cg->status == PurchaseClass::STATUS_SENDING) {
  515. // 构建“冲销”函数的参数 -- 变动前的花材存库数据
  516. $purchaseItems = PurchaseItemClass::getAllByCondition(['orderSn' => $cg->orderSn], null, "productId");
  517. $productIds = ArrayHelper::getColumn($purchaseItems, 'productId'); //$productIds 是本次入库涉及的花材ID数组
  518. $oldStocks = [];
  519. foreach ($productIds as $productId) {
  520. $product = ProductClass::getById($productId, true);
  521. $oldStocks[$productId] = $product;
  522. }
  523. PurchaseClass::takeToPutIn($cg);
  524. // “冲销”本次入库的数量
  525. PurchaseClass::rollbackProductStock($oldStocks, $shop, $adminId, $this->mainId, $this->shopAdmin->name);
  526. if ($doType == 1) {
  527. $transaction->commit();
  528. util::complete('入库成功');
  529. }
  530. } else {
  531. util::fail('订单不是待入库状态');
  532. }
  533. } else {
  534. if ($doType == 1) {
  535. util::fail('入库失败,没有找到采购单');
  536. }
  537. }
  538. }
  539. $ids = array_column($arr, 'id');
  540. $ids = array_unique(array_filter($ids));
  541. if (empty($ids)) {
  542. util::fail('请选择花材');
  543. }
  544. $sjId = $shop->sjId ?? 0;
  545. $chainShopList = [];
  546. if ($default == 1) {
  547. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  548. }
  549. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
  550. foreach ($arr as $product) {
  551. if (isset($product['price']) == false) {
  552. util::fail('没有价格');
  553. }
  554. if (isset($product['id']) == false) {
  555. util::fail('没有花材');
  556. }
  557. $price = $product['price'];
  558. $productId = $product['id'];
  559. $productInfo = $productList[$productId] ?? [];
  560. if (empty($productInfo)) {
  561. util::fail('没有找到花材');
  562. }
  563. $productName = $productInfo->name ?? '';
  564. if (isset($product['price']) == false || is_numeric($product['price']) == false || $product['price'] < 0) {
  565. util::fail('请填写' . $productName . '的批发价');
  566. }
  567. if (isset($product['skPrice']) == false || is_numeric($product['skPrice']) == false || $product['skPrice'] < 0) {
  568. util::fail('请填写' . $productName . '的零售价');
  569. }
  570. $skPrice = $product['skPrice'];
  571. if (isset($product['hjPrice']) == false || is_numeric($product['hjPrice']) == false || $product['hjPrice'] < 0) {
  572. util::fail('请填写' . $productName . '的会员价');
  573. }
  574. $hjPrice = $product['hjPrice'] ?? 0;
  575. if (isset($productInfo->mainId) == false || $productInfo->mainId != $this->mainId) {
  576. util::fail('无法访问。。');
  577. }
  578. if ($hjPrice > $price) {
  579. util::fail($productName . ' 批发价要大于会员价');
  580. }
  581. if ($price > $skPrice) {
  582. util::fail($productName . ' 零售价要大于批发价');
  583. }
  584. $ptItemId = $productInfo->itemId;
  585. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
  586. //在首店修改需要同步到所有直营店
  587. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  588. foreach ($chainShopList as $chain) {
  589. if ($chain->id == $shop->id) {
  590. continue;
  591. }
  592. $chainMainId = $chain->mainId ?? 0;
  593. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  594. $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
  595. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
  596. }
  597. }
  598. }
  599. $mainId = $shop->mainId ?? 0;
  600. if (!empty($mainId)) {
  601. //提醒零售收银台界面要刷新,多处要修改,关键词 modify_price_remind_cashier
  602. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  603. if (!empty($staffList)) {
  604. foreach ($staffList as $staff) {
  605. $staffId = $staff->id ?? 0;
  606. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  607. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  608. }
  609. }
  610. }
  611. $transaction->commit();
  612. util::complete('操作成功');
  613. } catch (\Exception $e) {
  614. $transaction->rollBack();
  615. Yii::info("失败原因:" . $e->getMessage());
  616. util::fail('修改失败');
  617. }
  618. }
  619. //从零售端采购入库,查看供货商的某个门店的product
  620. public function actionGhsItem()
  621. {
  622. $get = Yii::$app->request->get();
  623. $id = $get['id'] ?? 0;
  624. $ghs = GhsClass::getGhsInfo($id);
  625. if (empty($ghs)) {
  626. util::fail('没有找到供货商');
  627. }
  628. $shopId = $ghs['shopId'] ?? 0;
  629. $black = $ghs['black'] ?? 2;
  630. if ($black == 2) {
  631. util::fail('暂无花材');
  632. }
  633. $connection = Yii::$app->db;
  634. $transaction = $connection->beginTransaction();
  635. try {
  636. //获取所有当前供货商的分类 (全部、常用)
  637. //根据分类组装分类下的花材信息
  638. $shop = ShopClass::getById($shopId, true);
  639. $mainId = $shop->mainId ?? 0;
  640. $classIds = ItemClassClass::getGhsItemClassAll($mainId);
  641. $where['mainId'] = $mainId;
  642. $where['delStatus'] = 0;
  643. //是否显示全部花材,包括下架的
  644. $showAll = $get['showAll'] ?? 0;
  645. if ($showAll == 0) {
  646. $where['status'] = 1;
  647. }
  648. $where['frontHide'] = 0;
  649. $level = $ghs['giveLevel'] ?? 1;
  650. $field = 'id,py,cover,name,ratio,classId,itemId,weight,smallUnit,bigUnit,smallUnit,smallRatio,ratioType,variety,price,skPrice,skDiscountPrice,hjPrice,hjDiscountPrice,actualSold,stock,stockWarning,discountPrice,presell,presellDate,reachNum,reachNumDiscount,limitBuy,itemRemark';
  651. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  652. $itemInfoData = ProductClass::hdCgGroup($itemInfoData, $level, $ghs);
  653. $myProduct = ProductClass::getAllByCondition(['mainId' => $this->mainId, 'delStatus' => 0], null, 'id,stock,onStock,stockWarning,itemId', 'itemId');
  654. if (!empty($itemInfoData)) {
  655. $myShop = $this->shop;
  656. $myDisplay = isset($myShop->pfShopId) && $myShop->pfShopId > 0 ? 1 : 0;
  657. foreach ($itemInfoData as $key => $val) {
  658. $ptItemId = $val['itemId'] ?? 0;
  659. $myStock = $myProduct[$ptItemId]['stock'] ?? 0;
  660. $myStock = floatval($myStock);
  661. $myOnStock = $myProduct[$ptItemId]['onStock'] ?? 0;
  662. $myStockWarning = $myProduct[$ptItemId]['stockWarning'] ?? 5;
  663. $myLack = bcadd($myStock, $myOnStock, 2) > $myStockWarning ? 0 : 1;
  664. $itemInfoData[$key]['myStock'] = $myStock;
  665. $itemInfoData[$key]['myOnStock'] = $myOnStock;
  666. $itemInfoData[$key]['myStockWarning'] = $myStockWarning;
  667. $itemInfoData[$key]['myLack'] = $myLack;
  668. $itemInfoData[$key]['myDisplay'] = $myDisplay;
  669. }
  670. }
  671. $respond = ProductService::assembleData($classIds, $itemInfoData, true);
  672. $classItem = $respond['classItem'] ?? [];
  673. util::success($classItem);
  674. } catch (\Exception $e) {
  675. $transaction->rollBack();
  676. Yii::info("报错内容:" . $e->getMessage());
  677. util::fail();
  678. }
  679. }
  680. public function actionGhsItemV2()
  681. {
  682. $get = Yii::$app->request->get();
  683. $id = $get['id'] ?? 0;
  684. $ghs = GhsClass::getGhsInfo($id);
  685. if (empty($ghs)) {
  686. util::fail('没有找到供货商');
  687. }
  688. $shopId = $ghs['shopId'] ?? 0;
  689. $black = $ghs['black'] ?? 2;
  690. if ($black == 2) {
  691. util::fail('暂无花材');
  692. }
  693. $connection = Yii::$app->db;
  694. $transaction = $connection->beginTransaction();
  695. try {
  696. //获取所有当前供货商的分类 (全部、常用)
  697. //根据分类组装分类下的花材信息
  698. $shop = ShopClass::getById($shopId, true);
  699. $mainId = $shop->mainId ?? 0;
  700. $open = $shop->open ?? 1;
  701. $openStartTime = $shop->openStartTime;
  702. $openEndTime = $shop->openEndTime;
  703. if (!empty($openStartTime) && !empty($openEndTime)) {
  704. $date = date('Y-m-d');
  705. $openStartDate = $date . ' ' . $openStartTime;
  706. $openEndDate = $date . ' ' . $openEndTime;
  707. $startTime = strtotime($openStartDate);
  708. $endTime = strtotime($openEndDate);
  709. $currentTime = time();
  710. if ($currentTime < $startTime || $currentTime > $endTime) {
  711. $open = 0;
  712. }
  713. }
  714. if ($open == 0) {
  715. if (getenv('YII_ENV') == 'production') {
  716. //九江云朵、丽子鲜花、沈阳市云花鲜花,休店不让看花材
  717. if (in_array($mainId, [26374, 1496, 67094])) {
  718. util::fail('已休店');
  719. }
  720. } else {
  721. if (in_array($mainId, [644, 1])) {
  722. util::fail('已休店');
  723. }
  724. }
  725. }
  726. $classIds = ItemClassClass::getGhsItemClassAll($mainId);
  727. $where['mainId'] = $mainId;
  728. $where['delStatus'] = 0;
  729. //是否显示全部花材,包括下架的
  730. $showAll = $get['showAll'] ?? 0;
  731. if ($showAll == 0) {
  732. $where['status'] = 1;
  733. }
  734. $where['frontHide'] = 0;
  735. $level = $ghs['giveLevel'] ?? 1;
  736. $field = 'id,py,cover,name,ratio,classId,itemId,weight,smallUnit,bigUnit,smallUnit,smallRatio,ratioType,variety,price,skPrice,skDiscountPrice,hjPrice,hjDiscountPrice,avCost,actualSold,stock,stockWarning,discountPrice,presell,presellDate,reachNum,reachNumDiscount,limitBuy,itemRemark';
  737. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  738. $itemInfoData = ProductClass::hdCgGroup($itemInfoData, $level, $ghs);
  739. $myProduct = ProductClass::getAllByCondition(['mainId' => $this->mainId, 'delStatus' => 0], null, 'id,stock,onStock,stockWarning,itemId', 'itemId');
  740. if (!empty($itemInfoData)) {
  741. $myShop = $this->shop;
  742. $myDisplay = 0;
  743. if (isset($myShop->pfShopId) && $myShop->pfShopId > 0) {
  744. $myDisplay = 1;
  745. }
  746. foreach ($itemInfoData as $key => $val) {
  747. $ptItemId = $val['itemId'] ?? 0;
  748. $myStock = $myProduct[$ptItemId]['stock'] ?? 0;
  749. $myStock = floatval($myStock);
  750. $myOnStock = $myProduct[$ptItemId]['onStock'] ?? 0;
  751. $myStockWarning = $myProduct[$ptItemId]['stockWarning'] ?? 5;
  752. $myLack = bcadd($myStock, $myOnStock, 2) > $myStockWarning ? 0 : 1;
  753. $itemInfoData[$key]['myStock'] = $myStock;
  754. $itemInfoData[$key]['myOnStock'] = $myOnStock;
  755. $itemInfoData[$key]['myStockWarning'] = $myStockWarning;
  756. $itemInfoData[$key]['myLack'] = $myLack;
  757. $itemInfoData[$key]['myDisplay'] = $myDisplay;
  758. }
  759. }
  760. $respond = ProductService::assembleData($classIds, $itemInfoData, true);
  761. if ($showAll == 1) {
  762. if (isset($respond['classItem']) && !empty($respond['classItem'])) {
  763. foreach ($respond['classItem'] as $bigKey => $bigVal) {
  764. if (isset($bigVal['child']) && !empty($bigVal['child'])) {
  765. foreach ($bigVal['child'] as $key => $val) {
  766. unset($bigVal['child'][$key]['cover']);
  767. unset($bigVal['child'][$key]['actualSold']);
  768. unset($bigVal['child'][$key]['defaultGradePrice']);
  769. unset($bigVal['child'][$key]['discountPrice']);
  770. unset($bigVal['child'][$key]['hjDiscountPrice']);
  771. unset($bigVal['child'][$key]['hjPrice']);
  772. unset($bigVal['child'][$key]['presellDateShow']);
  773. unset($bigVal['child'][$key]['prePrice']);
  774. unset($bigVal['child'][$key]['print']);
  775. unset($bigVal['child'][$key]['reachNum']);
  776. unset($bigVal['child'][$key]['reachNumDiscount']);
  777. unset($bigVal['child'][$key]['reachPrice']);
  778. unset($bigVal['child'][$key]['skDiscountPrice']);
  779. unset($bigVal['child'][$key]['skPrice']);
  780. unset($bigVal['child'][$key]['bigUnit']);
  781. unset($bigVal['child'][$key]['weight']);
  782. unset($bigVal['child'][$key]['stockWarning']);
  783. //unset($bigVal['child'][$key]['smallPrice']);
  784. //unset($bigVal['child'][$key]['smallRatio']);
  785. }
  786. $respond['classItem'][$bigKey]['child'] = $bigVal['child'];
  787. }
  788. }
  789. }
  790. }
  791. util::success($respond);
  792. } catch (\Exception $e) {
  793. $transaction->rollBack();
  794. Yii::info("报错内容:" . $e->getMessage());
  795. util::fail();
  796. }
  797. }
  798. public function actionDetail()
  799. {
  800. $id = Yii::$app->request->get('id', 0);
  801. $respond = ProductClass::getItemInfo($id);
  802. if (empty($respond) || !is_array($respond)) {
  803. util::fail('没有找到花材');
  804. }
  805. $limitBuyClearInfo = \bizHd\product\classes\ProductClass::getLimitBuyClearInfo($id);
  806. if (!is_array($limitBuyClearInfo)) {
  807. $limitBuyClearInfo = [];
  808. }
  809. $respond['limitBuyClearInfo'] = $limitBuyClearInfo;
  810. $ptItemId = $respond['itemId'] ?? 0;
  811. $ptItemInfo = PtItemClass::getById($ptItemId);
  812. $respond['ptItemInfo'] = $ptItemInfo;
  813. // 封面图与多花材图片的兼容处理
  814. if ($respond['images'] == '' && $respond['shortCover'] != '') {
  815. $respond['images'] = $respond['shortCover'];
  816. }
  817. //查出拆散的子花材
  818. $part = UnitChangeClass::getByCondition(['big' => $id], true);
  819. $partAcceptItem = 0;
  820. $partAcceptItemName = '';
  821. if (!empty($part)) {
  822. $partAcceptItem = $part->small;
  823. $small = ProductClass::getByCondition(['id' => $partAcceptItem], true, false, 'id,name');
  824. $partAcceptItemName = $small->name ?? '';;
  825. }
  826. $respond['partAcceptItem'] = $partAcceptItem;
  827. $respond['partAcceptItemName'] = $partAcceptItemName;
  828. util::success($respond);
  829. }
  830. public function actionUpdate()
  831. {
  832. $shopAdmin = $this->shopAdmin;
  833. if (!isset($shopAdmin->super) || $shopAdmin->super != 1) {
  834. util::fail('超管才能操作');
  835. }
  836. $shop = $this->shop;
  837. $join = $shop->join ?? 0;
  838. $default = $shop->default ?? 0;
  839. if ($join == 0 && $default == 0) {
  840. //因为盘点不能将花材盘成0,所以这边放出入口允许创始人在分店修改分店的花材库存
  841. if ($shopAdmin->super != 1) {
  842. util::fail('请先开通超管权限');
  843. }
  844. }
  845. $deadline = $shop->deadline;
  846. $deadTime = strtotime($deadline);
  847. if (time() > $deadTime) {
  848. util::fail('系统已到期,编号563');
  849. }
  850. $post = Yii::$app->request->post();
  851. $discountPrice = $post['discountPrice'] ?? 0;
  852. if ($discountPrice > 0) {
  853. if (empty($post['hjDiscountPrice'])) {
  854. $addPrice = $post['addPrice'] ?? 0;
  855. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  856. $skMore = $post['skMore'] ?? 0;
  857. $diff = bcsub($addPrice, $hjAddPrice, 2);
  858. if ($diff > 0 && $discountPrice > $diff) {
  859. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  860. } else {
  861. $hjDiscountPrice = $discountPrice;
  862. }
  863. $diff = bcsub($skMore, $addPrice, 2);
  864. if ($diff > 0) {
  865. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  866. } else {
  867. $skDiscountPrice = $discountPrice;
  868. }
  869. $post['skDiscountPrice'] = $skDiscountPrice;
  870. $post['hjDiscountPrice'] = $hjDiscountPrice;
  871. }
  872. $reachNum = $post['reachNum'] ?? 0;
  873. $reachNumDiscount = $post['reachNumDiscount'] ?? 0;
  874. if ($reachNum > 0 && $reachNumDiscount > 0) {
  875. util::fail('特价和满减不能同时进行');
  876. }
  877. }
  878. $post['adminId'] = $this->adminId;
  879. $post['staffId'] = $this->shopAdmin->id;
  880. $post['staffName'] = $this->shopAdmin->name;
  881. //如果开启限购则必须升级应用
  882. $limitBuy = $post['limitBuy'] ?? 0;
  883. if ($limitBuy > 0) {
  884. $appVersion = $post['appVersion'] ?? 0;
  885. if ($appVersion < 2) {
  886. util::fail('请先升级,才能使用限购');
  887. }
  888. }
  889. $connection = Yii::$app->db;
  890. $transaction = $connection->beginTransaction();
  891. try {
  892. ProductClass::updateProduct($post, $this->shop, 'hd');
  893. $transaction->commit();
  894. util::complete();
  895. } catch (\Exception $e) {
  896. Yii::info("操作失败:" . $e->getMessage());
  897. $transaction->rollBack();
  898. util::fail('操作失败');
  899. }
  900. }
  901. //批量修改product 排序,成本价,加价
  902. public function actionBatchUpdate()
  903. {
  904. //data = [{id:1,inTurn:10,addPrice:2,cost:10}]
  905. $data = Yii::$app->request->post('data', '');
  906. $type = Yii::$app->request->post('type', '');
  907. if (empty($data) || empty($type)) {
  908. util::fail("参数错误");
  909. }
  910. if (in_array($type, ['inTurn', 'addPrice', 'cost', 'weight', 'ratio']))
  911. $data = json_decode($data, true);
  912. foreach ($data as $v) {
  913. $id = $v['id'];
  914. $val = $v[$type] ?? '';
  915. $where = [];
  916. $where['id'] = $id;
  917. $where['shopId'] = $this->shopId;
  918. $where['sjId'] = $this->sjId;
  919. if (empty($val)) {
  920. util::fail("参数错误1");
  921. }
  922. $data = [
  923. $type => $val
  924. ];
  925. ProductClass::updateByCondition($where, $data);
  926. ProductClass::autoPriceById($id);
  927. }
  928. util::complete();
  929. }
  930. //供货商产品的详情 ssh 20230111
  931. public function actionGhsProductDetail()
  932. {
  933. $get = Yii::$app->request->get();
  934. $id = $get['id'] ?? 0;
  935. $ghsId = $get['ghsId'] ?? 0;
  936. $product = ProductClass::getById($id);
  937. if (empty($product)) {
  938. util::fail('没有花材信息');
  939. }
  940. $ghsInfo = GhsClass::getById($ghsId, true, 'giveLevel');
  941. $level = isset($ghsInfo->giveLevel) ? $ghsInfo->giveLevel : 1;
  942. $list = ProductClass::groupProductInfo([$product], $level);
  943. $product = current($list);
  944. $mainId = $product['mainId'] ?? 0;
  945. $pixTextGoods = PicTextGhsItemClass::getByCondition(['mainId' => $mainId, 'ghsItemId' => $id], true);
  946. $product['picTextGoods'] = $pixTextGoods;
  947. // 封面图与多花材图片的兼容处理
  948. if ($product['images'] == '' && $product['shortCover'] != '') {
  949. $product['images'] = $product['shortCover'];
  950. }
  951. util::success($product);
  952. }
  953. //批量修改加价 ssh 20211211
  954. public function actionBatchChangeAddPrice()
  955. {
  956. $shopAdmin = $this->shopAdmin;
  957. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  958. util::fail('超管才能操作');
  959. }
  960. $shop = $this->shop;
  961. $pfShopId = $shop->pfShopId ?? 0;
  962. if (!empty($pfShopId)) {
  963. util::fail('请在批发端操作');
  964. }
  965. $addData = Yii::$app->request->post('addData', '');
  966. if (empty($addData)) {
  967. util::fail('没有花材');
  968. }
  969. $itemData = json_decode($addData, true);
  970. if (is_array($itemData) == false) {
  971. util::fail('没有花材...');
  972. }
  973. $ids = array_column($itemData, 'id');
  974. $infoList = ProductClass::getByIds($ids);
  975. if (empty($infoList)) {
  976. util::fail('没有花材');
  977. }
  978. foreach ($infoList as $info) {
  979. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  980. util::fail('非常访问,不是你的花材不能修改');
  981. }
  982. }
  983. foreach ($itemData as $key => $data) {
  984. $id = $data['id'] ?? 0;
  985. ProductClass::updateById($id, $data);
  986. }
  987. util::complete('修改成功');
  988. }
  989. //修改拆散接收的花材 ssh 20251124
  990. public function actionModifyPartAcceptItem()
  991. {
  992. $get = Yii::$app->request->get();
  993. $smallId = $get['small'] ?? 0;
  994. $bigId = $get['big'] ?? 0;
  995. $small = ProductClass::getById($smallId, true);
  996. if (empty($small)) {
  997. util::fail('子花材没找到');
  998. }
  999. $smallName = $small->name ?? '';
  1000. if ($small->mainId != $this->mainId) {
  1001. util::fail($smallName . '不是你的花材');
  1002. }
  1003. if ($small->ratio != 1) {
  1004. util::fail($smallName . '不是1支装的');
  1005. }
  1006. $big = ProductClass::getById($bigId, true);
  1007. if (empty($big)) {
  1008. util::fail('没有找到花材');
  1009. }
  1010. if ($big->mainId != $this->mainId) {
  1011. util::fail('不是你的花材呢');
  1012. }
  1013. $change = UnitChangeClass::getByCondition(['big' => $bigId], true);
  1014. if (empty($change)) {
  1015. UnitChangeClass::add(['big' => $bigId, 'small' => $smallId], true);
  1016. } else {
  1017. $change->small = $smallId;
  1018. $change->save();
  1019. }
  1020. util::complete('修改成功');
  1021. }
  1022. public function actionCancelDiscount()
  1023. {
  1024. $get = Yii::$app->request->get();
  1025. $id = $get['id'] ?? 0;
  1026. $info = ProductClass::getById($id, true);
  1027. ProductClass::check($info, $this->mainId);
  1028. $info->discountPrice = 0;
  1029. $info->skDiscountPrice = 0;
  1030. $info->hjDiscountPrice = 0;
  1031. $info->save();
  1032. util::complete('取消成功');
  1033. }
  1034. }