ProductController.php 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394
  1. <?php
  2. /**
  3. * User: admin
  4. * Date Time: 2021/1/15 20:36
  5. */
  6. namespace ghs\controllers;
  7. use biz\admin\classes\AdminRoleClass;
  8. use biz\item\classes\PtItemClass;
  9. use bizGhs\custom\classes\CustomClass;
  10. use bizGhs\item\classes\ItemClass;
  11. use bizGhs\item\classes\ItemClassClass;
  12. use bizGhs\merchant\classes\ShopClass;
  13. use bizGhs\notify\classes\NotifyClass;
  14. use bizGhs\order\classes\PurchaseOrderClass;
  15. use bizGhs\product\classes\ProductClass;
  16. use bizGhs\product\models\Product;
  17. use bizGhs\product\services\ProductService;
  18. use bizGhs\shop\classes\ShopAdminClass;
  19. use bizGhs\stock\classes\StockInDayClass;
  20. use common\components\printUtil;
  21. use common\components\stringUtil;
  22. use common\components\util;
  23. use Yii;
  24. class ProductController extends BaseController
  25. {
  26. public $guestAccess = ['index'];
  27. //停止预售 ssh 20230224
  28. public function actionCancelPreSell()
  29. {
  30. $get = Yii::$app->request->get();
  31. $id = $get['id'] ?? 0;
  32. $info = ProductClass::getById($id, true);
  33. ProductClass::check($info, $this->mainId);
  34. if ($info->stock > 0) {
  35. util::fail('没有库存才能停止预售');
  36. }
  37. $info->presell = 0;
  38. $info->presellDate = '';
  39. $info->save();
  40. util::complete();
  41. }
  42. //修改预售 ssh 20221214
  43. public function actionChangePresell()
  44. {
  45. $post = Yii::$app->request->post();
  46. $id = $post['id'] ?? 0;
  47. $info = ProductClass::getById($id, true);
  48. ProductClass::check($info, $this->mainId);
  49. $str = $post['date'] ?? '';
  50. $presell = $post['presell'] ?? 0;
  51. $newStr = '';
  52. if ($presell == 1) {
  53. if (empty($str)) {
  54. util::fail('请填写预售日期');
  55. }
  56. $arr = json_decode($str, true);
  57. if (empty($arr)) {
  58. util::fail('请填写预售日期');
  59. }
  60. $new = [];
  61. foreach ($arr as $date) {
  62. $new[] = strtotime($date);
  63. }
  64. $new = array_unique(array_filter($new));
  65. asort($new);
  66. $newStr = implode(',', $new);
  67. }
  68. $info->presell = $presell;
  69. $info->presellDate = $newStr;
  70. $info->discountPrice = 0;
  71. $info->save();
  72. util::complete();
  73. }
  74. //取消特价 ssh 20220901
  75. public function actionCancelDiscount()
  76. {
  77. $get = Yii::$app->request->get();
  78. $id = $get['id'] ?? 0;
  79. $info = ProductClass::getById($id, true);
  80. ProductClass::check($info, $this->mainId);
  81. $info->discountPrice = 0;
  82. $info->skDiscountPrice = 0;
  83. $info->hjDiscountPrice = 0;
  84. $info->save();
  85. util::complete();
  86. }
  87. //打印花材的标签 ssh 20220602
  88. public function actionPrint()
  89. {
  90. $get = Yii::$app->request->get();
  91. $id = $get['id'] ?? 0;
  92. $num = $get['num'] ?? 1;
  93. $type = $get['type'] ?? 0;
  94. $info = ProductClass::getById($id, true);
  95. if (empty($info)) {
  96. util::fail('没有找到花材');
  97. }
  98. $name = $info->name ?? '';
  99. $ptItemId = $info->itemId ?? 0;
  100. $mainId = $info->mainId ?? 0;
  101. $ext = $this->shopExt;
  102. $printLabelSn = $ext->printLabelSn ?? '';
  103. if (empty($printLabelSn)) {
  104. util::fail('请设置标签打印机');
  105. }
  106. $p = new printUtil($printLabelSn);
  107. $unit = $info->ratio . $info->smallUnit . '/' . $info->bigUnit;
  108. if (isset($info->ratioType) && $info->ratioType == 1) {
  109. $unit = '若干' . $info->smallUnit . '/' . $info->bigUnit;
  110. }
  111. $p->times = $num;
  112. if (stringUtil::getWordNum($name) > 7) {
  113. $content = '<TEXT x="30" y="30" font="12" w="1" h="1" r="0">' . $name . '</TEXT>';
  114. } else {
  115. $content = '<TEXT x="30" y="30" font="12" w="2" h="2" r="0">' . $name . '</TEXT>';
  116. }
  117. //杭州斗南批发店
  118. if (isset($get['type']) == false && $this->shopId == 4608) {
  119. $content .= '<QR x="35" y="100" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $id . '</QR>';
  120. $content .= '<TEXT x="40" y="270" font="12" w="1" h="1" r="0">扫码看价格</TEXT>';
  121. } else {
  122. if ($type == 0) {
  123. //打标签
  124. $content .= '<BC128 x="30" y="115" h="75" s="1" r="0" n="3" w="10">' . $ptItemId . '</BC128>';
  125. if (in_array($mainId, [52, 1459])) {
  126. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">惠雅鲜花</TEXT>';
  127. } else {
  128. $content .= '<TEXT x="30" y="250" font="12" w="2" h="2" r="0">' . $unit . '</TEXT>';
  129. }
  130. } else {
  131. //打价码
  132. $content .= '<QR x="35" y="100" e="L" w="5">' . Yii::$app->params['mallHost'] . "/item/show-info?id=" . $id . '</QR>';
  133. $content .= '<TEXT x="40" y="270" font="12" w="1" h="1" r="0">扫码看价格</TEXT>';
  134. }
  135. }
  136. $p->printLabelMsg($content);
  137. util::complete();
  138. }
  139. //取出今天有入库的花材 ssh 20221024
  140. public function actionStockIn()
  141. {
  142. $py = Yii::$app->request->get('py', '');
  143. $version = Yii::$app->request->get('version', 0);
  144. if ($version == 0) {
  145. util::fail('请先升级版本到1.0.70以上');
  146. }
  147. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  148. $mainId = $this->mainId ?? 0;
  149. $where['mainId'] = $mainId;
  150. if ($py) {
  151. $pyName = strtolower($py);
  152. $where['py'] = $pyName;
  153. }
  154. $arr = StockInDayClass::getAllByCondition(['mainId' => $mainId], null, '*');
  155. if (empty($arr)) {
  156. util::fail('没有花材需要盘点');
  157. }
  158. $ids = array_column($arr, 'itemId');
  159. $ids = array_unique($ids);
  160. $where['id'] = ['in', $ids];
  161. $level = 1;
  162. $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell,presellDate';
  163. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  164. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  165. $data = ProductService::assembleData($classInfo, $itemInfoData, true);
  166. util::success($data);
  167. }
  168. //按分类列出所有花材
  169. public function actionShow()
  170. {
  171. $py = Yii::$app->request->get('py', '');
  172. $requestType = Yii::$app->request->get('requestType', 'common');
  173. //默认显示上架商品
  174. $status = Yii::$app->request->get('status', 1);
  175. //默认显示未删除商品
  176. $delStatus = Yii::$app->request->get('delStatus', 0);
  177. //获取所有当前供货商的分类 (全部、常用)
  178. //根据分类组装分类下的花材信息
  179. //中央ID
  180. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  181. $where['mainId'] = $this->mainId;
  182. if ($py) {
  183. $pyName = strtolower($py);
  184. $where['py'] = $pyName;
  185. }
  186. //改价和全部有库存花材列表
  187. if ($requestType == 'changePrice' || $requestType == 'hasStockList') {
  188. $where['stock>'] = 0;
  189. }
  190. if (!empty($status)) {
  191. $where['status'] = $status;
  192. }
  193. $where['delStatus'] = $delStatus;
  194. //客户等级
  195. $customId = Yii::$app->request->get('customId', 0);
  196. $level = 1;
  197. if (!empty($customId)) {
  198. $custom = CustomClass::getById($customId, true);
  199. $level = $custom->level ?? 1;
  200. }
  201. $notShowFrontHide = ProductClass::getNotShowFrontHideMainIds();
  202. $itemInfoData = [];
  203. if ($requestType == 'hasStockList') {
  204. //有库存的花材列表
  205. $field = 'id,py,name,classId,itemId,price,skPrice,hjPrice,stock';
  206. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  207. } elseif ($requestType == 'changePrice') {
  208. if (in_array($this->mainId, $notShowFrontHide)) {
  209. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,hjPrice,discountPrice,hjDiscountPrice,skDiscountPrice,skMore,hjAddPrice,addPrice,variety,price,hjPrice,stock,presell';
  210. } else {
  211. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,hjPrice,discountPrice,hjDiscountPrice,skDiscountPrice,skMore,hjAddPrice,addPrice,variety,price,hjPrice,stock,presell,frontHide';
  212. }
  213. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  214. $itemInfoData = ProductClass::changePriceGroup($itemInfoData, $level);
  215. } elseif ($requestType == 'changeStock') {
  216. //修改库存列表
  217. $field = 'id,py,cover,name,cost,itemId,status,classId,addPrice,skPrice,discountPrice,skMore,variety,price,stock,frontHide';
  218. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  219. $itemInfoData = ProductClass::changeStockGroup($itemInfoData, $level);
  220. } elseif ($requestType == 'kd') {
  221. //开单的花材列表
  222. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,hjDiscountPrice,skDiscountPrice,discountPrice,stock,weight,stockWarning,presell,ratioType,smallUnit,smallRatio,bigUnit,ratio,frontHide';
  223. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  224. $itemInfoData = ProductClass::kdItemGroup($itemInfoData, $level);
  225. } elseif ($requestType == 'book') {
  226. //预订花材列表
  227. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,hjDiscountPrice,skDiscountPrice,discountPrice,stock,weight,stockWarning,presell,ratioType,smallUnit,smallRatio,bigUnit,ratio,frontHide';
  228. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  229. $itemInfoData = ProductClass::itemListGroup($itemInfoData, $level);
  230. } elseif ($requestType == 'itemList') {
  231. //花材列表
  232. if (in_array($this->mainId, $notShowFrontHide)) {
  233. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,discountPrice,hjDiscountPrice,skDiscountPrice,stock,actualSold,status,ratio,ratioType,presell';
  234. } else {
  235. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,hjPrice,discountPrice,hjDiscountPrice,skDiscountPrice,stock,actualSold,status,ratio,ratioType,presell,frontHide';
  236. }
  237. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  238. $itemInfoData = ProductClass::itemListGroup($itemInfoData, $level);
  239. } elseif ($requestType == 'outList') {
  240. //下架花材列表
  241. $where['status'] = 2;
  242. $where['delStatus'] = 0;
  243. $where['removeStatus'] = 0;
  244. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
  245. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  246. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  247. } elseif ($requestType == 'stopList') {
  248. //停用花材列表
  249. unset($where['status']);
  250. $where['delStatus'] = 1;
  251. $where['removeStatus'] = 0;
  252. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
  253. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  254. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  255. } elseif ($requestType == 'removeList') {
  256. //删除花材列表
  257. unset($where['status']);
  258. $where['delStatus'] = 1;
  259. $where['removeStatus'] = 1;
  260. $field = 'id,py,cover,name,cost,itemId,classId,addPrice,skPrice,bigUnit,smallUnit,ratio,ratioType,discountPrice,skMore,variety,price,stock,presell,status';
  261. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  262. $itemInfoData = ProductClass::simpleGroup($itemInfoData, $level);
  263. } elseif ($requestType == 'check') {
  264. //盘点花材列表
  265. if (in_array($this->mainId, $notShowFrontHide)) {
  266. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  267. } else {
  268. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,frontHide';
  269. }
  270. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  271. $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
  272. } elseif ($requestType == 'break') {
  273. if (in_array($this->mainId, $notShowFrontHide)) {
  274. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  275. } else {
  276. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,frontHide';
  277. }
  278. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  279. $itemInfoData = ProductClass::breakItemGroup($itemInfoData, $level);
  280. } elseif ($requestType == 'part') {
  281. //拆散花材
  282. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  283. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  284. $itemInfoData = ProductClass::partItemGroup($itemInfoData, $level);
  285. } elseif ($requestType == 'stockOut') {
  286. if (in_array($this->mainId, $notShowFrontHide)) {
  287. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,smallRatio';
  288. } else {
  289. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio,smallRatio,frontHide';
  290. }
  291. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  292. $itemInfoData = ProductClass::stockOutGroup($itemInfoData, $level);
  293. } elseif ($requestType == 'cg') {
  294. if (in_array($this->mainId, $notShowFrontHide)) {
  295. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,presell,ratioType,smallUnit,bigUnit,ratio,weight';
  296. } else {
  297. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,presell,ratioType,smallUnit,bigUnit,ratio,weight,frontHide';
  298. }
  299. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  300. $itemInfoData = ProductClass::cgItemGroup($itemInfoData, $level);
  301. } elseif ($requestType == 'warning') {
  302. if (in_array($this->mainId, $notShowFrontHide)) {
  303. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,discountPrice,stock,actualSold,presell,bigUnit,stockWarning,status';
  304. } else {
  305. $field = 'id,py,cover,name,cost,itemId,classId,skPrice,variety,price,discountPrice,stock,actualSold,presell,bigUnit,stockWarning,status,frontHide';
  306. }
  307. $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  308. ->andWhere('`stock`<`stockWarning`')
  309. ->andWhere("delStatus=0")
  310. ->select($field)->asArray()->all();
  311. $itemInfoData = ProductClass::warningGroup($itemInfoData, $level);
  312. } else {
  313. util::fail('没有数据');
  314. }
  315. $data = ProductService::assembleItemData($classInfo, $itemInfoData);
  316. util::success($data);
  317. }
  318. //取出今天有入库的花材 ssh 20221224
  319. public function actionGetStockIn()
  320. {
  321. $py = Yii::$app->request->get('py', '');
  322. $version = Yii::$app->request->get('version', 0);
  323. if ($version == 0) {
  324. util::fail('请先升级版本到1.0.70以上');
  325. }
  326. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  327. $mainId = $this->mainId ?? 0;
  328. $where['mainId'] = $mainId;
  329. if ($py) {
  330. $pyName = strtolower($py);
  331. $where['py'] = $pyName;
  332. }
  333. $arr = StockInDayClass::getAllByCondition(['mainId' => $mainId], null, '*');
  334. if (empty($arr)) {
  335. util::fail('没有花材需要盘点');
  336. }
  337. $ids = array_column($arr, 'itemId');
  338. $ids = array_unique($ids);
  339. $where['id'] = ['in', $ids];
  340. $level = 1;
  341. $field = 'id,py,cover,name,itemId,classId,variety,price,discountPrice,stock,stockWarning,presell,ratioType,smallUnit,bigUnit,ratio';
  342. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  343. $itemInfoData = ProductClass::checkItemGroup($itemInfoData, $level);
  344. $data = ProductService::assembleItemData($classInfo, $itemInfoData);
  345. util::success($data);
  346. }
  347. //按分类列出所有花材
  348. public function actionIndex()
  349. {
  350. $py = Yii::$app->request->get('py', '');
  351. $requestType = Yii::$app->request->get('requestType', 'common');
  352. //默认显示上架商品
  353. $status = Yii::$app->request->get('status', 1);
  354. //默认显示未删除商品
  355. $delStatus = Yii::$app->request->get('delStatus', 0);
  356. $warning = Yii::$app->request->get('warning', 0);
  357. //获取所有当前供货商的分类 (全部、常用)
  358. //根据分类组装分类下的花材信息
  359. //中央ID
  360. $classInfo = ItemClassClass::getGhsItemClassAll($this->mainId);
  361. $where['mainId'] = $this->mainId;
  362. if ($py) {
  363. $pyName = strtolower($py);
  364. $where['py'] = $pyName;
  365. }
  366. if ($requestType == 'hasStock') {
  367. //改价只显示库存大于0的
  368. $where['stock>'] = 0;
  369. }
  370. if (!empty($status)) {
  371. $where['status'] = $status;
  372. }
  373. $where['delStatus'] = $delStatus;
  374. //客户等级
  375. $customId = Yii::$app->request->get('customId', 0);
  376. $level = 1;
  377. if (!empty($customId)) {
  378. $custom = CustomClass::getById($customId, true);
  379. $level = $custom->level ?? 1;
  380. }
  381. if ($warning == 1) {
  382. //库存预警
  383. $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell';
  384. $itemInfoData = Product::find()->where("mainId={$this->mainId}")
  385. ->andWhere('`stock`<`stockWarning`')
  386. ->andWhere("delStatus=0")
  387. ->select($field)->asArray()->all();
  388. } else {
  389. $field = 'id,py,cover,name,ratio,cost,addPrice,classId,skMore,skPrice,itemId,smallUnit,smallRatio,presellDate,bigUnit,smallUnit,ratioType,variety,price,stock,stockWarning,discountPrice,presell';
  390. $itemInfoData = ProductClass::getAllByCondition($where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC], $field);
  391. }
  392. $itemInfoData = ProductClass::groupProductInfo($itemInfoData, $level);
  393. $data = ProductService::assembleData($classInfo, $itemInfoData, true);
  394. util::success($data);
  395. }
  396. //所有花材分页和不分页
  397. public function actionList()
  398. {
  399. $where = [];
  400. $classId = Yii::$app->request->get('classId', 0);
  401. if (!empty($classId)) {
  402. $where['classId'] = $classId;
  403. }
  404. $name = Yii::$app->request->get('name', '');
  405. if (empty($name)) {
  406. $py = Yii::$app->request->get('py', '');
  407. $name = !empty($py) ? $py : '';
  408. }
  409. if (!empty($name)) {
  410. if (stringUtil::isLetter($name)) {
  411. $where['py'] = ['like', $name];
  412. } else {
  413. $where['name'] = ['like', $name];
  414. }
  415. }
  416. $status = Yii::$app->request->get('status', 0);
  417. if (!empty($status)) {
  418. $where['status'] = $status;
  419. }
  420. $delStatus = Yii::$app->request->get('delStatus', 0);
  421. if ($delStatus != 2) {
  422. $where['delStatus'] = $delStatus;
  423. }
  424. $where['mainId'] = $this->mainId;
  425. $productIds = Yii::$app->request->get('ids', '');
  426. if (!empty($productIds)) {
  427. $productIdArr = explode(',', $productIds);
  428. if (!empty($productIdArr)) {
  429. $where['id'] = ['in', $productIdArr];
  430. }
  431. }
  432. //输出标准会员价,即批发价,默认显示的是批发价
  433. $level = 1;
  434. $type = Yii::$app->request->get('type', '');
  435. $showPage = Yii::$app->request->get('showPage', 0);
  436. if ($showPage) {
  437. if ($type == 'waring') {
  438. $pro = Product::find()->where("mainId={$this->mainId}")->andWhere('`stock`<`stockWarning`')->select('id')->asArray()->all();
  439. $lackIds = array_column($pro, 'id');
  440. if (empty($lackIds)) {
  441. util::success([]);
  442. }
  443. $lackIds = array_filter(array_unique($lackIds));
  444. $where['id'] = ['in', $lackIds];
  445. $respond = ProductClass::getList("*", $where, "actualSold desc");
  446. } else {
  447. $respond = ProductClass::getList("*", $where, "inTurn desc");
  448. }
  449. $respond['list'] = ProductClass::groupProductInfo($respond['list'], $level);
  450. $respond['list'] = ProductClass::groupClassName($this->sjId, $respond['list']);
  451. util::success($respond);
  452. } else {
  453. if ($type == 'waring') {
  454. //库存预警 按库存从小到大排序
  455. $data = ProductClass::getAllByCondition($where, ['stock' => SORT_ASC, 'inTurn' => SORT_DESC], "*");
  456. } else {
  457. if (!empty($productIds)) {
  458. //优先按 $productIds 排序 "FIELD(`id`,4,5,6)"=>true
  459. $data = ProductClass::getAllByCondition($where, ["FIELD(`id`,$productIds)" => true, 'inTurn' => SORT_DESC], "*");
  460. } else {
  461. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  462. }
  463. }
  464. $data = ProductClass::groupProductInfo($data, $level);
  465. $data = ProductClass::groupClassName($this->sjId, $data);
  466. if ($type == 'waring') {
  467. //库存预警
  468. $newData = [];
  469. foreach ($data as $v) {
  470. if ($v['stock'] <= $v['stockWarning']) {
  471. $newData[] = $v;
  472. }
  473. }
  474. util::success(['list' => $newData]);
  475. }
  476. util::success(['list' => $data]);
  477. }
  478. }
  479. //所有花材
  480. public function actionAll()
  481. {
  482. $where = [];
  483. $where['mainId'] = $this->mainId;
  484. $classId = Yii::$app->request->get('classId', 0);
  485. if (!empty($classId)) {
  486. $where['classId'] = $classId;
  487. }
  488. $status = Yii::$app->request->get('status', 0);
  489. if (!empty($status)) {
  490. $where['status'] = $status;
  491. }
  492. $delStatus = Yii::$app->request->get('delStatus', 0);
  493. if ($delStatus != 2) {
  494. $where['delStatus'] = $delStatus;
  495. }
  496. //输出标准会员价,即批发价,默认显示的是批发价
  497. $level = 1;
  498. $data = ProductClass::getAllByCondition($where, ['actualSold' => SORT_DESC, 'inTurn' => SORT_DESC], "*");
  499. $data = ProductClass::groupProductInfo($data, $level);
  500. util::success(['list' => $data]);
  501. }
  502. //批量改价
  503. public function actionBatchChangePrice()
  504. {
  505. $shop = $this->shop;
  506. $join = $shop->join ?? 0;
  507. $default = $shop->default ?? 0;
  508. if ($join == 0 && $default == 0) {
  509. util::fail('当前直营分店,只能回总店修改价格');
  510. }
  511. $shopAdmin = $this->shopAdmin;
  512. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  513. util::fail('超管才能修改');
  514. }
  515. $shop = $this->shop;
  516. $default = $shop->default ?? 0;
  517. $adminId = $this->adminId ?? 0;
  518. //normal常规改价,cg采购改价
  519. $changeType = Yii::$app->request->post('changeType', 'normal');
  520. $targetId = Yii::$app->request->post('targetId', 0);
  521. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  522. $post = Yii::$app->request->post();
  523. $data = $post['data'] ?? '';
  524. if (empty($data)) {
  525. util::fail('没有修改');
  526. }
  527. $arr = json_decode($data, true);
  528. if (empty($arr)) {
  529. util::fail('没有修改哦');
  530. }
  531. $appVersion = $post['appVersion'] ?? 0;
  532. if ($appVersion != 1) {
  533. util::fail('请先升级应用');
  534. }
  535. $connection = Yii::$app->db;
  536. $transaction = $connection->beginTransaction();
  537. try {
  538. $cg = PurchaseOrderClass::getLockById($targetId);
  539. if (!empty($cg)) {
  540. if (isset($cg->mainId) == false || $cg->mainId != $this->mainId) {
  541. util::fail('不是您的采购单');
  542. }
  543. //批量改价同时入库
  544. if ($cg->status == PurchaseOrderClass::PURCHASE_ORDER_STATUS_SENDING) {
  545. $staff = $this->shopAdmin;
  546. $data = [];
  547. $data['staffId'] = $staff->id ?? 0;
  548. $data['staffName'] = $staff->name ?? '';
  549. $data['adminId'] = $this->adminId ?? 0;
  550. PurchaseOrderClass::putIn($cg, $data);
  551. }
  552. }
  553. $ids = array_column($arr, 'id');
  554. $ids = array_unique(array_filter($ids));
  555. if (empty($ids)) {
  556. util::fail('请选择花材');
  557. }
  558. $sjId = $shop->sjId ?? 0;
  559. $chainShopList = [];
  560. if ($default == 1) {
  561. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  562. }
  563. $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id', true);
  564. foreach ($arr as $product) {
  565. $productId = $product['id'];
  566. $productInfo = $productList[$productId] ?? [];
  567. if (empty($productInfo)) {
  568. util::fail('没有找到花材');
  569. }
  570. $productName = $productInfo->name ?? '';
  571. if (isset($product['id']) == false) {
  572. util::fail('没有花材');
  573. }
  574. if (isset($product['price']) == false || is_numeric($product['price']) == false || $product['price'] < 0) {
  575. util::fail('请填写' . $productName . '的批发价');
  576. }
  577. $price = $product['price'];
  578. if (isset($product['skPrice']) == false || is_numeric($product['skPrice']) == false || $product['skPrice'] < 0) {
  579. util::fail('请填写' . $productName . '的零售价');
  580. }
  581. $skPrice = $product['skPrice'];
  582. if (isset($product['hjPrice']) == false || is_numeric($product['hjPrice']) == false || $product['hjPrice'] < 0) {
  583. util::fail('请填写' . $productName . '的会员价');
  584. }
  585. $hjPrice = $product['hjPrice'] ?? 0;
  586. if (isset($productInfo->mainId) == false || $productInfo->mainId != $this->mainId) {
  587. util::fail('无法访问');
  588. }
  589. if ($hjPrice > $price) {
  590. util::fail($productName . ' 批发价要大于会员价');
  591. }
  592. if ($price > $skPrice) {
  593. util::fail($productName . ' 零售价要大于批发价');
  594. }
  595. $ptItemId = $productInfo->itemId;
  596. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
  597. //在首店修改需要同步到所有直营店
  598. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  599. foreach ($chainShopList as $chain) {
  600. if ($chain->id == $shop->id) {
  601. continue;
  602. }
  603. $chainMainId = $chain->mainId ?? 0;
  604. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  605. $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
  606. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
  607. }
  608. }
  609. }
  610. $mainId = $shop->mainId ?? 0;
  611. if (!empty($mainId)) {
  612. //提醒零售收银台界面要刷新
  613. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  614. if (!empty($staffList)) {
  615. foreach ($staffList as $staff) {
  616. $staffId = $staff->id ?? 0;
  617. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  618. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  619. }
  620. }
  621. }
  622. $transaction->commit();
  623. util::complete('操作成功');
  624. } catch (\Exception $e) {
  625. $transaction->rollBack();
  626. Yii::info("修改失败原因:" . $e->getMessage());
  627. util::fail('修改失败');
  628. }
  629. }
  630. //多个花材同时改成一个价 ssh 20231003
  631. public function actionManyItemChangeOnePrice()
  632. {
  633. $shop = $this->shop;
  634. $join = $shop->join ?? 0;
  635. $default = $shop->default ?? 0;
  636. if ($join == 0 && $default == 0) {
  637. util::fail('当前直营分店,只能回总店修改价格');
  638. }
  639. $shopAdmin = $this->shopAdmin;
  640. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  641. util::fail('超管才能修改');
  642. }
  643. $post = Yii::$app->request->post();
  644. $idsList = $post['ids'] ?? '';
  645. $ids = json_decode($idsList, true);
  646. if (empty($ids)) {
  647. util::fail('请选择花材');
  648. }
  649. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  650. if (empty($list)) {
  651. util::fail('请选择花材哦');
  652. }
  653. $mainId = $this->mainId;
  654. $adminId = $this->adminId ?? 0;
  655. $shop = $this->shop;
  656. $default = $shop->default ?? 0;
  657. $shopAdmin = $this->shopAdmin;
  658. $price = $post['price'] ?? 0;
  659. if (is_numeric($price) == false) {
  660. util::fail('批发价填写错误');
  661. }
  662. $skPrice = $post['skPrice'] ?? 0;
  663. if (is_numeric($skPrice) == false) {
  664. util::fail('散客价填写错误');
  665. }
  666. $hjPrice = $post['hjPrice'] ?? 0;
  667. if (is_numeric($hjPrice) == false) {
  668. util::fail('会员价填写错误');
  669. }
  670. if ($hjPrice > $price) {
  671. util::fail('会员价不能大于批发价');
  672. }
  673. if ($price > $skPrice) {
  674. util::fail('批发价不能大于零售价');
  675. }
  676. $sjId = $shop->sjId ?? 0;
  677. $chainShopList = [];
  678. if ($default == 1) {
  679. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  680. }
  681. //normal常规改价,cg采购改价
  682. $changeType = Yii::$app->request->post('changeType', 'normal');
  683. $targetId = 0;
  684. $changeParams = ['staffId' => $shopAdmin->id, 'staffName' => $shopAdmin->name, 'changeType' => $changeType, 'targetId' => $targetId];
  685. $connection = Yii::$app->db;
  686. $transaction = $connection->beginTransaction();
  687. try {
  688. foreach ($list as $product) {
  689. if ($product->mainId != $mainId) {
  690. util::fail('修改失败,不是你的花材');
  691. }
  692. $ptItemId = $product->itemId;
  693. ProductClass::changeSinglePrice($shop, $ptItemId, $price, $skPrice, $hjPrice, $changeParams);
  694. //在首店修改需要同步到所有直营店
  695. if ($default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  696. if (!empty($chainShopList)) {
  697. foreach ($chainShopList as $chain) {
  698. if ($chain->id == $shop->id) {
  699. continue;
  700. }
  701. $chainMainId = $chain->mainId ?? 0;
  702. $staff = ShopAdminClass::getByCondition(['mainId' => $chainMainId, 'adminId' => $adminId], true);
  703. $changeParams2 = ['staffId' => $staff->id, 'staffName' => $staff->name, 'changeType' => $changeType, 'targetId' => $targetId];
  704. ProductClass::changeSinglePrice($chain, $ptItemId, $price, $skPrice, $hjPrice, $changeParams2);
  705. }
  706. }
  707. }
  708. }
  709. if (!empty($mainId)) {
  710. //提醒零售收银台界面要刷新
  711. $staffList = ShopAdminClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  712. if (!empty($staffList)) {
  713. foreach ($staffList as $staff) {
  714. $staffId = $staff->id ?? 0;
  715. Yii::$app->redis->executeCommand('SET', ['cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  716. Yii::$app->redis->executeCommand('SET', ['ghs_cashier_' . $mainId . '_' . $staffId . '_may_refresh', 'yes']);
  717. }
  718. }
  719. }
  720. $transaction->commit();
  721. util::complete('修改成功');
  722. } catch (\Exception $e) {
  723. $transaction->rollBack();
  724. Yii::info("修改失败原因:" . $e->getMessage());
  725. util::fail('修改失败');
  726. }
  727. }
  728. //改价
  729. public function actionChangePrice()
  730. {
  731. $shopAdmin = $this->shopAdmin;
  732. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  733. util::fail('超管才能修改');
  734. }
  735. $productId = Yii::$app->request->post('productId', 0);
  736. $productInfo = ProductClass::getById($productId, true);
  737. if (empty($productInfo)) {
  738. util::fail("花材不存在");
  739. }
  740. if ($productInfo->mainId != $this->mainId) {
  741. util::fail('没有权限');
  742. }
  743. $price = Yii::$app->request->post('price', '');
  744. if (is_numeric($price) && $price > 0) {
  745. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_CHANGE);
  746. } else {
  747. $price = bcadd($productInfo->cost, $productInfo->addPrice, 2);
  748. ProductClass::changeSinglePrice($productInfo, $price, ProductClass::PRICE_LABEL_AUTO);
  749. }
  750. util::success(['price' => $price]);
  751. }
  752. //恢复自动调价
  753. public function actionAutoPrice()
  754. {
  755. $productId = Yii::$app->request->post('productId', 0);
  756. $productData = ProductClass::getById($productId);
  757. if (!$productData) {
  758. util::fail("花材不存在");
  759. }
  760. //2021.04.06改为用product中的成本价+加价
  761. $price = bcadd($productData['cost'], $productData['addPrice'], 2);
  762. ProductClass::changeSinglePrice($productId, $this->shopId, $price, ProductClass::PRICE_LABEL_AUTO);
  763. util::complete("操作成功");
  764. }
  765. //修改加价
  766. public function actionChangeAddPrice()
  767. {
  768. $productId = Yii::$app->request->post('productId', 0);
  769. $addPrice = Yii::$app->request->post('addPrice', '');
  770. if ($addPrice < 0) {
  771. util::fail("加价不能小于0");
  772. }
  773. $productData = ProductClass::getProductData($productId, $this->mainId);
  774. if (!$productData) {
  775. util::fail("花材不存在");
  776. }
  777. ProductClass::changeAddPrice($productId, $addPrice);
  778. util::complete();
  779. }
  780. //批量修改更多,包括排序、重量和保质期 ssh 20211211
  781. public function actionBatchChangeMore()
  782. {
  783. $shop = $this->shop;
  784. $default = $shop->default ?? 0;
  785. if ($default == 0) {
  786. util::fail('当前直营分店,请返回总店修改');
  787. }
  788. $shopAdmin = $this->shopAdmin;
  789. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  790. util::fail('超管才能操作');
  791. }
  792. $addData = Yii::$app->request->post('addData', '');
  793. if (empty($addData)) {
  794. util::fail('没有花材');
  795. }
  796. $itemData = json_decode($addData, true);
  797. if (is_array($itemData) == false) {
  798. util::fail('没有花材...');
  799. }
  800. $ids = array_column($itemData, 'id');
  801. $infoList = ProductClass::getByIds($ids, null, 'id');
  802. if (empty($infoList)) {
  803. util::fail('没有花材');
  804. }
  805. foreach ($infoList as $info) {
  806. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  807. util::fail('不是你的花材不能修改');
  808. }
  809. }
  810. //总店修改同步到所有门店
  811. $sjId = $shop->sjId ?? 0;
  812. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  813. foreach ($itemData as $key => $data) {
  814. $id = $data['id'] ?? 0;
  815. unset($data['id']);
  816. ProductClass::updateById($id, $data);
  817. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  818. if (empty($ptItemId)) {
  819. continue;
  820. }
  821. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  822. foreach ($chainShopList as $chainShop) {
  823. $currentMainId = $chainShop->mainId ?? 0;
  824. if ($currentMainId == $shop->mainId) {
  825. //前面已经修改过了,不需要重复修改
  826. continue;
  827. }
  828. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  829. }
  830. }
  831. }
  832. util::complete('修改成功');
  833. }
  834. //批量修改加价 ssh 20211211
  835. public function actionBatchChangeAddPrice()
  836. {
  837. $shop = $this->shop;
  838. $join = $shop->join ?? 0;
  839. $default = $shop->default ?? 0;
  840. if ($join == 0 && $default == 0) {
  841. util::fail('当前直营分店,请切回总店操作');
  842. }
  843. $shopAdmin = $this->shopAdmin;
  844. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  845. util::fail('超管才能操作');
  846. }
  847. $post = Yii::$app->request->post();
  848. $addData = $post['addData'] ?? '';
  849. if (empty($addData)) {
  850. util::fail('没有花材');
  851. }
  852. $itemData = json_decode($addData, true);
  853. if (is_array($itemData) == false) {
  854. util::fail('没有花材...');
  855. }
  856. $ids = array_column($itemData, 'id');
  857. $infoList = ProductClass::getByIds($ids, null, 'id');
  858. if (empty($infoList)) {
  859. util::fail('没有花材');
  860. }
  861. foreach ($infoList as $info) {
  862. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  863. util::fail('不能修改别人的花材');
  864. }
  865. }
  866. $appVersion = $post['appVersion'] ?? 0;
  867. if ($appVersion != 1) {
  868. util::fail('请先升级应用');
  869. }
  870. //总店修改同步到所有门店
  871. $sjId = $shop->sjId ?? 0;
  872. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  873. foreach ($itemData as $key => $data) {
  874. $id = $data['id'] ?? 0;
  875. unset($data['id']);
  876. ProductClass::updateById($id, $data);
  877. $ptItemId = $infoList[$id]['itemId'] ?? 0;
  878. if (empty($ptItemId)) {
  879. continue;
  880. }
  881. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  882. foreach ($chainShopList as $chainShop) {
  883. if (isset($chainShop->join) && $chainShop->join == 1) {
  884. continue;
  885. }
  886. $currentMainId = $chainShop->mainId ?? 0;
  887. if ($currentMainId == $shop->mainId) {
  888. //前面已经修改过了,不需要重复修改
  889. continue;
  890. }
  891. ProductClass::updateByCondition(['mainId' => $currentMainId, 'itemId' => $ptItemId], $data);
  892. }
  893. }
  894. }
  895. util::complete('修改成功');
  896. }
  897. public function actionUpdate()
  898. {
  899. $shopAdmin = $this->shopAdmin;
  900. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  901. util::fail('超管才能操作');
  902. }
  903. $shop = $this->shop;
  904. $join = $shop->join ?? 0;
  905. $default = $shop->default ?? 0;
  906. if ($join == 0 && $default == 0) {
  907. //因为盘点不能将花材盘成0,所以这边放出入口允许创始人在分店修改分店的花材库存
  908. if ($shopAdmin->super != 1) {
  909. util::fail('请先开通超管权限');
  910. }
  911. }
  912. $post = Yii::$app->request->post();
  913. //临时兼容,2023.7.1后可以删除
  914. $appVersion = $post['appVersion'] ?? 0;
  915. if ($appVersion != 1) {
  916. util::fail('请先升级应用');
  917. }
  918. $discountPrice = $post['discountPrice'] ?? 0;
  919. if ($discountPrice > 0) {
  920. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  921. $addPrice = $post['addPrice'] ?? 0;
  922. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  923. $skMore = $post['skMore'] ?? 0;
  924. $diff = bcsub($addPrice, $hjAddPrice, 2);
  925. if ($diff > 0 && $discountPrice > $diff) {
  926. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  927. } else {
  928. $hjDiscountPrice = $discountPrice;
  929. }
  930. $diff = bcsub($skMore, $addPrice, 2);
  931. if ($diff > 0) {
  932. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  933. } else {
  934. $skDiscountPrice = $discountPrice;
  935. }
  936. $post['skDiscountPrice'] = $skDiscountPrice;
  937. $post['hjDiscountPrice'] = $hjDiscountPrice;
  938. }
  939. }
  940. $post['adminId'] = $this->adminId;
  941. $post['staffId'] = $this->shopAdmin->id;
  942. $post['staffName'] = $this->shopAdmin->name;
  943. ProductClass::updateProduct($post, $this->shop);
  944. util::complete();
  945. }
  946. //上下架状态控制 ssh 20210713
  947. public function actionStatusUpdate()
  948. {
  949. $post = Yii::$app->request->post();
  950. $shopAdmin = $this->shopAdmin;
  951. $roleId = $shopAdmin['roleId'] ?? 0;
  952. $role = AdminRoleClass::getById($roleId);
  953. $roleName = $role['roleName'] ?? '';
  954. if ($roleName == '员工') {
  955. util::fail('无法操作哦');
  956. }
  957. $id = $post['id'] ?? 0;
  958. $status = $post['status'] ?? 1;
  959. $product = ProductClass::getById($id, true);
  960. if ($product->mainId != $this->mainId) {
  961. util::fail('无法操作');
  962. }
  963. $product->status = $status;
  964. if ($status == 2) {
  965. $product->discountPrice = 0;
  966. }
  967. $product->save();
  968. util::complete();
  969. }
  970. //花材展示状态控制 ssh 20231113
  971. public function actionDelStatusUpdate()
  972. {
  973. $post = Yii::$app->request->post();
  974. $shop = $this->shop;
  975. $join = $shop->join ?? 0;
  976. $default = $shop->default ?? 0;
  977. if ($join == 0 && $default == 0) {
  978. util::fail('请在首店操作');
  979. }
  980. $id = $post['id'] ?? 0;
  981. $delStatus = $post['delStatus'] ?? 0;
  982. $product = ProductClass::getById($id, true);
  983. if ($product->mainId != $this->mainId) {
  984. util::fail('不是你的花材哦!!');
  985. }
  986. $product->delStatus = $delStatus;
  987. if ($delStatus == 1) {
  988. $product->stock = 0;
  989. $product->status = 2;
  990. }
  991. $product->save();
  992. $ptItemId = $product->itemId ?? 0;
  993. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  994. //总店修改同步到所有门店
  995. $sjId = $shop->sjId ?? 0;
  996. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  997. foreach ($chainShopList as $chainShop) {
  998. $chainShopId = $chainShop->id ?? 0;
  999. if (isset($chainShop->join) && $chainShop->join == 1) {
  1000. continue;
  1001. }
  1002. if ($chainShopId == $shop->id) {
  1003. continue;
  1004. }
  1005. $chainMainId = $chainShop->mainId ?? 0;
  1006. $chainProduct = ProductClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
  1007. if (!empty($chainProduct)) {
  1008. $chainProduct->delStatus = $delStatus;
  1009. if ($delStatus == 1) {
  1010. $chainProduct->stock = 0;
  1011. $chainProduct->status = 2;
  1012. }
  1013. $chainProduct->save();
  1014. }
  1015. }
  1016. }
  1017. util::complete();
  1018. }
  1019. //详情 ruidian 2021.5.3
  1020. public function actionDetail()
  1021. {
  1022. $id = Yii::$app->request->get('id', 0);
  1023. $source = Yii::$app->request->get('source', '');
  1024. $respond = ProductClass::getItemInfo($id);
  1025. $ptItemId = $respond['itemId'] ?? 0;
  1026. $ptItemInfo = PtItemClass::getById($ptItemId);
  1027. $respond['ptItemInfo'] = $ptItemInfo;
  1028. if ($source == 'notify' && $respond['mainId'] == $this->mainId) {
  1029. $staff = $this->shopAdmin;
  1030. $staffId = $this->shopAdminId;
  1031. $notify = NotifyClass::getByCondition(['staffId' => $staffId, 'type' => 1, 'targetId' => $id], true);
  1032. if (!empty($notify)) {
  1033. if ($notify->read == 0) {
  1034. $notify->read = 1;
  1035. $notify->save();
  1036. $notifyNum = $staff->notifyNum;
  1037. if ($notifyNum > 0) {
  1038. $notifyNum--;
  1039. $staff->notifyNum = $notifyNum;
  1040. $staff->save();
  1041. }
  1042. }
  1043. }
  1044. }
  1045. util::success($respond);
  1046. }
  1047. //新增花材 2021.6.21
  1048. public function actionAdd()
  1049. {
  1050. $post = Yii::$app->request->post();
  1051. //临时兼容,2023.7.1后可以删除
  1052. $appVersion = $post['appVersion'] ?? 0;
  1053. if ($appVersion != 1) {
  1054. util::fail('请先升级应用');
  1055. }
  1056. $discountPrice = $post['discountPrice'] ?? 0;
  1057. if ($discountPrice > 0) {
  1058. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  1059. $addPrice = $post['addPrice'] ?? 0;
  1060. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  1061. $skMore = $post['skMore'] ?? 0;
  1062. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1063. if ($diff > 0 && $discountPrice > $diff) {
  1064. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1065. } else {
  1066. $hjDiscountPrice = $discountPrice;
  1067. }
  1068. $diff = bcsub($skMore, $addPrice, 2);
  1069. if ($diff > 0) {
  1070. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1071. } else {
  1072. $skDiscountPrice = $discountPrice;
  1073. }
  1074. $post['skDiscountPrice'] = $skDiscountPrice;
  1075. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1076. }
  1077. }
  1078. $shop = $this->shop;
  1079. $join = $shop->join ?? 0;
  1080. $default = $shop->default ?? 0;
  1081. if ($join == 0 && $default == 0) {
  1082. util::fail('当前直营分店,请切回总店添加花材');
  1083. }
  1084. $shopAdmin = $this->shopAdmin;
  1085. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1086. util::fail('管理员才能添加花材');
  1087. }
  1088. $post['sjId'] = $this->sjId;
  1089. $post['adminId'] = $this->adminId;
  1090. $post['mainId'] = $this->mainId;
  1091. $price = $post['price'] ?? 0;
  1092. $addPrice = $post['addPrice'] ?? 0;
  1093. if ($addPrice > $price) {
  1094. util::fail('加价不能大于售价');
  1095. }
  1096. $weight = isset($post['weight']) && is_numeric($post['weight']) ? $post['weight'] : 0;
  1097. if ($weight <= 0) {
  1098. util::fail('请填写重量,最小0.1');
  1099. }
  1100. $post['staffName'] = $shopAdmin->name ?? '';
  1101. ProductClass::addProduct($post, $this->shop);
  1102. util::complete('添加成功');
  1103. }
  1104. //获取拼音缩写 ssh 20210707
  1105. public function actionPy()
  1106. {
  1107. $name = Yii::$app->request->get('name');
  1108. $py = stringUtil::py($name);
  1109. util::success(['py' => $py]);
  1110. }
  1111. //(客户端-批发商)复制花材
  1112. public function actionClone()
  1113. {
  1114. $post = Yii::$app->request->post();
  1115. $appVersion = $post['appVersion'] ?? 0;
  1116. if ($appVersion != 1) {
  1117. util::fail('请先升级应用');
  1118. }
  1119. $discountPrice = $post['discountPrice'] ?? 0;
  1120. if ($discountPrice > 0) {
  1121. if (isset($post['hjDiscountPrice']) == false || empty($post['hjDiscountPrice'])) {
  1122. $addPrice = $post['addPrice'] ?? 0;
  1123. $hjAddPrice = $post['hjAddPrice'] ?? 0;
  1124. $skMore = $post['skMore'] ?? 0;
  1125. $diff = bcsub($addPrice, $hjAddPrice, 2);
  1126. if ($diff > 0 && $discountPrice > $diff) {
  1127. $hjDiscountPrice = bcsub($discountPrice, $diff, 2);
  1128. } else {
  1129. $hjDiscountPrice = $discountPrice;
  1130. }
  1131. $diff = bcsub($skMore, $addPrice, 2);
  1132. if ($diff > 0) {
  1133. $skDiscountPrice = bcadd($diff, $discountPrice, 2);
  1134. } else {
  1135. $skDiscountPrice = $discountPrice;
  1136. }
  1137. $post['skDiscountPrice'] = $skDiscountPrice;
  1138. $post['hjDiscountPrice'] = $hjDiscountPrice;
  1139. }
  1140. }
  1141. $shop = $this->shop;
  1142. $join = $shop->join ?? 0;
  1143. $default = $shop->default ?? 0;
  1144. if ($join == 0 && $default == 0) {
  1145. util::fail('请在首店操作');
  1146. }
  1147. $shopAdmin = $this->shopAdmin;
  1148. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1149. util::fail('管理员才能添加花材');
  1150. }
  1151. $post['sjId'] = $this->sjId;
  1152. $post['adminId'] = $this->adminId;
  1153. $post['mainId'] = $this->mainId;
  1154. $post['staffName'] = $shopAdmin->name ?? '';
  1155. $price = $post['price'] ?? 0;
  1156. if (empty($price) || $price <= 0) {
  1157. util::fail('请填写批发价');
  1158. }
  1159. $skPrice = $post['skPrice'] ?? 0;
  1160. if (empty($skPrice) || $skPrice <= 0) {
  1161. util::fail('请填写零售价');
  1162. }
  1163. $hjPrice = $post['hjPrice'] ?? 0;
  1164. if (empty($hjPrice) || $hjPrice <= 0) {
  1165. util::fail('请填写会员价');
  1166. }
  1167. $addPrice = $post['addPrice'] ?? 0;
  1168. if ($addPrice > $price) {
  1169. util::fail('批发价的加价不能大于售价');
  1170. }
  1171. //复制标识
  1172. $post['copy'] = 1;
  1173. //去除无用的字段
  1174. unset($post['viewNum']);
  1175. unset($post['actualSold']);
  1176. unset($post['itemId']);
  1177. unset($post['id']);
  1178. unset($post['delStatus']);
  1179. ProductClass::addProduct($post, $this->shop);
  1180. util::complete('复制成功');
  1181. }
  1182. //下载价格表 ssh 20210922
  1183. public function actionGeneratePriceTable()
  1184. {
  1185. $level = Yii::$app->request->get('level', 0);
  1186. $respond = ProductService::generatePriceTable($this->sjId, $level, $this->mainId);
  1187. $file = $respond['file'] ?? '';
  1188. $shortFile = $respond['shortFile'] ?? '';
  1189. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1190. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1191. }
  1192. public function actionGenerateItemTable()
  1193. {
  1194. $level = Yii::$app->request->get('level', 0);
  1195. $respond = ProductService::generateItemTable($this->sjId, $level, $this->mainId);
  1196. $file = $respond['file'] ?? '';
  1197. $shortFile = $respond['shortFile'] ?? '';
  1198. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1199. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1200. }
  1201. //下载条形码 lqh 20211227
  1202. public function actionGenerateBarcodeTable()
  1203. {
  1204. $respond = ProductService::generateBarcodeTable($this->sjId, $this->shopId, $this->mainId);
  1205. $file = $respond['file'] ?? '';
  1206. $shortFile = $respond['shortFile'] ?? '';
  1207. $fileUrl = Yii::$app->params['ghsHost'] . $file;
  1208. util::success(['file' => $fileUrl, 'shortFile' => $shortFile]);
  1209. }
  1210. //批量修改花材的分类 ssh 20230405
  1211. public function actionBatchModifyClass()
  1212. {
  1213. $post = Yii::$app->request->post();
  1214. $shop = $this->shop;
  1215. $join = $shop->join ?? 0;
  1216. $default = $shop->default ?? 0;
  1217. if ($join == 0 && $default == 0) {
  1218. util::fail('当前直营分店,请切回总店操作');
  1219. }
  1220. $classId = $post['classId'] ?? 0;
  1221. $class = ItemClassClass::getById($classId, true);
  1222. if (empty($class) || $class->mainId != $this->mainId) {
  1223. util::fail('请选择您自己的分类');
  1224. }
  1225. $connection = Yii::$app->db;
  1226. $transaction = $connection->beginTransaction();
  1227. try {
  1228. $className = $class->name ?? '';
  1229. $idsList = $post['ids'] ?? '';
  1230. $ids = json_decode($idsList, true);
  1231. if (empty($ids)) {
  1232. util::fail('请选择花材');
  1233. }
  1234. $list = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
  1235. if (empty($list)) {
  1236. util::fail('请选择花材');
  1237. }
  1238. $ptItemList = [];
  1239. foreach ($list as $item) {
  1240. $name = $item->name ?? '';
  1241. if ($item->mainId != $this->mainId) {
  1242. util::fail($name . '不是您的花材');
  1243. }
  1244. $item->classId = $classId;
  1245. $item->save();
  1246. $ptItemId = $item->itemId ?? 0;
  1247. $ptItemList[] = $ptItemId;
  1248. }
  1249. $shop = $this->shop;
  1250. if (isset($shop->default) && $shop->default == 1 && isset($shop->dataSync) && $shop->dataSync == 1) {
  1251. //总店修改同步到所有门店
  1252. $sjId = $shop->sjId ?? 0;
  1253. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId], null, '*', null, true);
  1254. foreach ($chainShopList as $chainShop) {
  1255. $chainShopId = $chainShop->id ?? 0;
  1256. if ($chainShopId == $shop->id) {
  1257. continue;
  1258. }
  1259. $chainManId = $chainShop->mainId ?? 0;
  1260. $chainAllClassList = ItemClassClass::getAllByCondition(['mainId' => $chainManId], null, '*', null, true);
  1261. if (!empty($chainAllClassList)) {
  1262. foreach ($chainAllClassList as $chainClass) {
  1263. $chainName = $chainClass->name ?? '';
  1264. $chainClassId = $chainClass->id ?? 0;
  1265. if ($chainName == $className) {
  1266. $chainProductList = Productclass::getAllByCondition(['mainId' => $chainManId, 'itemId' => ['in', $ptItemList]], null, '*', null, true);
  1267. if (!empty($chainProductList)) {
  1268. foreach ($chainProductList as $currentProduct) {
  1269. $currentProduct->classId = $chainClassId;
  1270. $currentProduct->save();
  1271. }
  1272. }
  1273. }
  1274. }
  1275. }
  1276. }
  1277. }
  1278. $transaction->commit();
  1279. util::complete('修改成功');
  1280. } catch (\Exception $e) {
  1281. $transaction->rollBack();
  1282. Yii::info("修改失败原因:" . $e->getMessage());
  1283. util::fail('修改失败');
  1284. }
  1285. }
  1286. }