ProductService.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. <?php
  2. namespace App\Service;
  3. use App\Model\BasicType;
  4. use App\Model\Depart;
  5. use App\Model\Employee;
  6. use App\Model\Product;
  7. use App\Model\ProductCategory;
  8. use App\Model\ProductInfo;
  9. use App\Model\ProductIntroduction;
  10. use App\Model\ProductInventory;
  11. use App\Model\ProductPriceDetail;
  12. use App\Model\ProductRange;
  13. use Illuminate\Support\Facades\DB;
  14. /**
  15. * 产品管理
  16. */
  17. class ProductService extends Service
  18. {
  19. /**
  20. * 产品分类编辑
  21. * @param $data
  22. * @param $user
  23. * @return array
  24. */
  25. public function productCategoryEdit($data,$user){
  26. list($status,$msg) = $this->productCategoryRule($data,$user,false);
  27. if(!$status) return [$status,$msg];
  28. $update = $msg['data'][0];
  29. $model = new ProductCategory();
  30. $model->where('id',$data['id'])->update($update);
  31. return [true,''];
  32. }
  33. /**
  34. * 产品分类新增
  35. * @param $data
  36. * @param $user
  37. * @return array
  38. */
  39. public function productCategoryAdd($data,$user){
  40. list($status,$msg) = $this->productCategoryRule($data,$user);
  41. if(!$status) return [$status,$msg];
  42. ProductCategory::insert($msg['data']);
  43. return [true,''];
  44. }
  45. /**
  46. * 产品分类删除
  47. * @param $data
  48. * @return array
  49. */
  50. public function productCategoryDel($data){
  51. if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
  52. $bool = Product::where('del_time',0)
  53. ->where('product_category_id',$data['id'])
  54. ->exists();
  55. if($bool) return [false,'产品分类下已添加产品,操作失败'];
  56. try {
  57. DB::beginTransaction();
  58. ProductCategory::where('id',$data['id'])->update([
  59. 'del_time' => time()
  60. ]);
  61. DB::commit();
  62. }catch (\Exception $exception){
  63. DB::rollBack();
  64. return [false,$exception->getMessage()];
  65. }
  66. return [true,''];
  67. }
  68. /**
  69. * 产品分类列表
  70. * @param $data
  71. * @param $user
  72. * @return array
  73. */
  74. public function productCategoryList($data,$user){
  75. $model = new ProductCategory(['userData' => $user, 'search' => $data]);
  76. $model = $model->where('del_time',0)
  77. ->select('title','id','parent_id')
  78. ->orderby('id','desc');
  79. if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
  80. $list = $this->limit($model,'',$data);
  81. return [true, $list];
  82. }
  83. /**
  84. * 产品分类参数规则
  85. * @param $data
  86. * @param $is_add
  87. * @return array
  88. */
  89. public function productCategoryRule($data,$user, $is_add = true){
  90. if($this->isEmpty($data,'data')) return [false,'数据不能为空!'];
  91. //所属部门 以及 顶级部门
  92. if(empty($data['depart_id'])) $data['depart_id'] = $this->getDepart($user);
  93. $data['top_depart_id'] = $user['depart_map'][$data['depart_id']] ?? 0;
  94. $title = array_column($data['data'],'title');
  95. $title = array_map(function($val) {
  96. return $val !== null ? $val : 0;
  97. }, $title);
  98. $title_count = array_count_values($title);
  99. foreach ($title as $value){
  100. if(empty($value)) return [false,'名称不能为空!'];
  101. if($title_count[$value] > 1) return [false,'名称不能重复'];
  102. }
  103. foreach ($data['data'] as $key => $value){
  104. $data['data'][$key]['upd_time'] = time();
  105. if($is_add){
  106. $parent_id = 0;
  107. if(! empty($value['parent_id'])) {
  108. $bool = Product::where('del_time',0)
  109. ->where('product_category_id',$value['parent_id'])
  110. ->exists();
  111. if($bool) {
  112. $title = ProductCategory::where('id',$value['parent_id'])->select('title')->value('title');
  113. return [false,'产品分类:'. $title .'下已添加产品,不允许添加子分类'];
  114. }
  115. $parent_id = $value['parent_id'];
  116. }
  117. $data['data'][$key]['parent_id'] = $parent_id;
  118. $data['data'][$key]['crt_time'] = time();
  119. $data['data'][$key]['depart_id'] = $data['depart_id'];
  120. $data['data'][$key]['top_depart_id'] = $data['top_depart_id'];
  121. $bool = ProductCategory::where('title',$value['title'])
  122. ->where('top_depart_id',$data['top_depart_id'])
  123. ->where('del_time',0)
  124. ->exists();
  125. }else{
  126. if($this->isEmpty($data,'id')) return [false,'id不能为空!'];
  127. $bool = ProductCategory::where('title',$value['title'])
  128. ->where('top_depart_id',$data['top_depart_id'])
  129. ->where('id','<>',$data['id'])
  130. ->where('del_time',0)
  131. ->exists();
  132. }
  133. if($bool) return [false,'分类名称不能重复'];
  134. }
  135. return [true, $data];
  136. }
  137. /**
  138. * 产品编辑
  139. * @param $data
  140. * @param $user
  141. * @return array
  142. */
  143. public function productEdit($data,$user){
  144. list($status,$msg) = $this->productRule($data, $user, false);
  145. if(!$status) return [$status,$msg];
  146. try {
  147. DB::beginTransaction();
  148. $model = Product::where('id',$data['id'])->first();
  149. $model->product_category_id = $data['product_category_id'] ?? 0;
  150. $model->title = $data['title'];
  151. $model->code = $data['code'] ?? '';
  152. $model->size = $data['size'] ?? '';
  153. $model->unit = $data['unit'] ?? 0;
  154. $model->bar_code = $data['bar_code'] ?? '';
  155. $model->cost = $data['cost'] ?? 0;
  156. $model->retail_price = $data['retail_price'] ?? 0;
  157. $model->mark = $data['mark'] ?? '';
  158. $model->state = $data['state'] ?? 0;
  159. $model->save();
  160. $time = time();
  161. ProductIntroduction::where('product_id',$data['id'])
  162. ->where('del_time',0)
  163. ->update(['del_time' => $time]);
  164. if(! empty($data['introduction'])){
  165. $models = new ProductIntroduction();
  166. $models->product_id = $model->id;
  167. $models->introduction = $data['introduction'];
  168. $models->save();
  169. }
  170. ProductInfo::where('del_time',0)
  171. ->where('product_id',$data['id'])
  172. ->update(['del_time' => $time]);
  173. if(! empty($data['img'])){
  174. $insert = [];
  175. foreach ($data['img'] as $value){
  176. $insert[] = [
  177. 'product_id' => $model->id,
  178. 'file' => $value['url'],
  179. 'type' => ProductInfo::type_one,
  180. 'name' => $value['name'],
  181. 'crt_time' => $time,
  182. ];
  183. }
  184. ProductInfo::insert($insert);
  185. }
  186. if(! empty($data['file'])){
  187. $insert = [];
  188. foreach ($data['file'] as $value){
  189. $insert[] = [
  190. 'product_id' => $model->id,
  191. 'file' => $value['url'],
  192. 'type' => ProductInfo::type_two,
  193. 'name' => $value['name'],
  194. 'crt_time' => $time,
  195. ];
  196. }
  197. ProductInfo::insert($insert);
  198. }
  199. ProductRange::where('del_time',0)
  200. ->where('product_id',$data['id'])
  201. ->update(['del_time' => $time]);
  202. if(! empty($data['depart'])){
  203. $insert = [];
  204. foreach ($data['depart'] as $value){
  205. $insert[] = [
  206. 'product_id' => $model->id,
  207. 'depart_id' => $value,
  208. 'type' => ProductRange::type_one,
  209. 'crt_time' => $time,
  210. ];
  211. }
  212. ProductRange::insert($insert);
  213. }
  214. if(! empty($data['employee'])){
  215. $insert = [];
  216. foreach ($data['employee'] as $value){
  217. $insert[] = [
  218. 'product_id' => $model->id,
  219. 'employee_id' => $value,
  220. 'type' => ProductRange::type_two,
  221. 'crt_time' => $time,
  222. ];
  223. }
  224. ProductRange::insert($insert);
  225. }
  226. ProductPriceDetail::where('del_time',0)
  227. ->where('product_id',$data['id'])
  228. ->update(['del_time' => $time]);
  229. if(! empty($data['product_price'])){
  230. $insert = [];
  231. foreach ($data['product_price'] as $value){
  232. $insert[] = [
  233. 'product_id' => $model->id,
  234. 'basic_type_id' => $value['basic_type_id'],
  235. 'price' => $value['price'],
  236. 'crt_time' => $time,
  237. ];
  238. }
  239. ProductPriceDetail::insert($insert);
  240. }
  241. DB::commit();
  242. }catch (\Exception $exception){
  243. DB::rollBack();
  244. return [false,$exception->getMessage()];
  245. }
  246. return [true,''];
  247. }
  248. /**
  249. * 产品新增
  250. * @param $data
  251. * @param $user
  252. * @return array
  253. */
  254. public function productAdd($data,$user){
  255. list($status,$msg) = $this->productRule($data, $user);
  256. if(!$status) return [$status,$msg];
  257. try {
  258. DB::beginTransaction();
  259. $model = new Product();
  260. $model->product_category_id = $data['product_category_id'] ?? 0;
  261. $model->title = $data['title'];
  262. $model->code = $data['code'] ?? '';
  263. $model->size = $data['size'] ?? '';
  264. $model->unit = $data['unit'] ?? 0;
  265. $model->bar_code = $data['bar_code'] ?? '';
  266. $model->cost = $data['cost'] ?? 0;
  267. $model->retail_price = $data['retail_price'] ?? 0;
  268. $model->mark = $data['mark'] ?? '';
  269. $model->state = $data['state'] ?? 0;
  270. $model->crt_id = $user['id'];
  271. $model->depart_id = $data['depart_id'] ?? 0;
  272. $model->top_depart_id = $data['top_depart_id'] ?? 0;
  273. $model->save();
  274. $time = time();
  275. if(! empty($data['introduction'])){
  276. $models = new ProductIntroduction();
  277. $models->product_id = $model->id;
  278. $models->introduction = $data['introduction'];
  279. $models->save();
  280. }
  281. if(! empty($data['img'])){
  282. $insert = [];
  283. foreach ($data['img'] as $value){
  284. $insert[] = [
  285. 'product_id' => $model->id,
  286. 'file' => $value['url'],
  287. 'type' => ProductInfo::type_one,
  288. 'name' => $value['name'],
  289. 'crt_time' => $time,
  290. ];
  291. }
  292. ProductInfo::insert($insert);
  293. }
  294. if(! empty($data['file'])){
  295. $insert = [];
  296. foreach ($data['file'] as $value){
  297. $insert[] = [
  298. 'product_id' => $model->id,
  299. 'file' => $value['url'],
  300. 'type' => ProductInfo::type_two,
  301. 'name' => $value['name'],
  302. 'crt_time' => $time,
  303. ];
  304. }
  305. ProductInfo::insert($insert);
  306. }
  307. if(! empty($data['depart'])){
  308. $insert = [];
  309. foreach ($data['depart'] as $value){
  310. $insert[] = [
  311. 'product_id' => $model->id,
  312. 'depart_id' => $value,
  313. 'type' => ProductRange::type_one,
  314. 'crt_time' => $time,
  315. ];
  316. }
  317. ProductRange::insert($insert);
  318. }
  319. if(! empty($data['employee'])){
  320. $insert = [];
  321. foreach ($data['employee'] as $value){
  322. $insert[] = [
  323. 'product_id' => $model->id,
  324. 'employee_id' => $value,
  325. 'type' => ProductRange::type_two,
  326. 'crt_time' => $time,
  327. ];
  328. }
  329. ProductRange::insert($insert);
  330. }
  331. if(! empty($data['product_price'])){
  332. $insert = [];
  333. foreach ($data['product_price'] as $value){
  334. $insert[] = [
  335. 'product_id' => $model->id,
  336. 'basic_type_id' => $value['basic_type_id'],
  337. 'price' => $value['price'],
  338. 'crt_time' => $time,
  339. ];
  340. }
  341. ProductPriceDetail::insert($insert);
  342. }
  343. DB::commit();
  344. }catch (\Exception $exception){
  345. DB::rollBack();
  346. return [false,$exception->getMessage()];
  347. }
  348. return [true,''];
  349. }
  350. /**
  351. * 产品删除
  352. * @param $data
  353. * @return array
  354. */
  355. public function productDel($data){
  356. if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
  357. try {
  358. DB::beginTransaction();
  359. $time = time();
  360. Product::where('del_time',0)->where('id',$data['id'])->update(['del_time' => $time]);
  361. ProductIntroduction::where('product_id',$data['id'])
  362. ->where('del_time',0)
  363. ->update(['del_time' => $time]);
  364. ProductInfo::where('del_time',0)
  365. ->where('product_id',$data['id'])
  366. ->update(['del_time' => $time]);
  367. ProductRange::where('del_time',0)
  368. ->where('product_id',$data['id'])
  369. ->update(['del_time' => $time]);
  370. ProductPriceDetail::where('del_time',0)
  371. ->where('product_id',$data['id'])
  372. ->update(['del_time' => $time]);
  373. DB::commit();
  374. }catch (\Exception $exception){
  375. DB::rollBack();
  376. return [false,$exception->getMessage()];
  377. }
  378. return [true,''];
  379. }
  380. /**
  381. * 产品详情
  382. * @param $data
  383. * @param $user
  384. * @return array
  385. */
  386. public function productDetail($data,$user){
  387. if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
  388. $customer = Product::where('del_time',0)
  389. ->where('id',$data['id'])
  390. ->first();
  391. if(empty($customer)) return [false,'产品不存在或已被删除'];
  392. $customer = $customer->toArray();
  393. $category = ProductCategory::where('id',$customer['product_category_id'])
  394. ->value('title');
  395. $customer['product_category_title'] = $category;
  396. $customer['introduction'] = "";
  397. $in = ProductIntroduction::where('del_time',0)
  398. ->where('product_id',$data['id'])
  399. ->first();
  400. if(! empty($in)) $customer['introduction'] = $in->introduction;
  401. $detail = ProductPriceDetail::where('del_time',0)
  402. ->where('product_id',$data['id'])
  403. ->select('product_id','basic_type_id','price')
  404. ->get()->toArray();
  405. $title_map = BasicType::whereIn('id',array_column($detail,'basic_type_id'))
  406. ->pluck('title','id')
  407. ->toArray();
  408. //是否总公司
  409. $is_main = $user['is_all_depart'];
  410. $top_depart = $user['depart_top'][0] ?? [];
  411. $customer['is_edit'] = $customer['top_depart_id'] == $top_depart['depart_id'] ? 1 : 0;
  412. $customer['product_price'] = [];
  413. //展示金额
  414. foreach ($detail as $value){
  415. if(! $is_main && ($top_depart['basic_type_id'] != $value['basic_type_id'])) {
  416. $is_show = 0;
  417. }else{
  418. $is_show = 1;
  419. }
  420. $customer['product_price'][] = [
  421. 'basic_type_id' => $value['basic_type_id'],
  422. 'basic_type_title' => $title_map[$value['basic_type_id']] ?? '',
  423. 'price' => $value['price'],
  424. 'is_show' => $is_show,
  425. ];
  426. }
  427. //单位
  428. $title = BasicType::where('id',$customer['unit'])->value('title');
  429. $customer['unit_name'] = $title;
  430. $customer['img'] = $customer['file'] = $customer['depart'] = $customer['employee'] = [];
  431. $customer_info = ProductInfo::where('del_time',0)
  432. ->where('product_id',$customer['id'])
  433. ->select('id','product_id','file','type','name')
  434. ->get()->toArray();
  435. foreach ($customer_info as $value){
  436. $tmp = [
  437. 'url' => $value['file'],
  438. 'name' => $value['name'],
  439. ];
  440. if($value['type'] == ProductInfo::type_one){
  441. $customer['img'][] = $tmp;
  442. }elseif ($value['type'] == ProductInfo::type_two){
  443. $customer['file'][] = $tmp;
  444. }
  445. }
  446. $customer_range = ProductRange::where('del_time',0)
  447. ->where('product_id',$customer['id'])
  448. ->select('id','product_id','depart_id','type','employee_id')
  449. ->get()->toArray();
  450. $emp_map = Employee::whereIn('id',array_unique(array_merge_recursive([$customer['crt_id']],array_column($customer_range,'employee_id'))))
  451. ->pluck('emp_name','id')
  452. ->toArray();
  453. $depart_map = Depart::whereIn('id',array_unique(array_column($customer_range,'depart_id')))
  454. ->pluck('title','id')
  455. ->toArray();
  456. foreach ($customer_range as $value){
  457. if($value['type'] == ProductRange::type_one){
  458. $tmp = [
  459. 'id' => $value['depart_id'],
  460. 'name' => $depart_map[$value['depart_id']],
  461. ];
  462. $customer['depart'][] = $tmp;
  463. }elseif ($value['type'] == ProductRange::type_two){
  464. $tmp = [
  465. 'id' => $value['employee_id'],
  466. 'name' => $emp_map[$value['employee_id']] ?? '',
  467. ];
  468. $customer['employee'][] = $tmp;
  469. }
  470. }
  471. $customer['crt_name'] = $emp_map[$customer['crt_id']] ?? '';
  472. $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
  473. return [true, $customer];
  474. }
  475. /**
  476. * 产品列表
  477. * @param $data
  478. * @param $user
  479. * @return array
  480. */
  481. public function productList($data,$user){
  482. $model = new Product(['userData' => $user, 'search' => $data]);
  483. $model = $model->where('del_time',0)
  484. ->select('title','id','product_category_id','code','size','unit','bar_code','retail_price','cost','state','crt_id','crt_time','mark','depart_id','top_depart_id')
  485. ->orderby('id', 'desc');
  486. if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
  487. if(isset($data['state'])) $model->where('state', $data['state']);
  488. $list = $this->limit($model,'',$data);
  489. $list = $this->fillData($list,$user);
  490. return [true, $list];
  491. }
  492. /**
  493. * 产品参数规则
  494. * @param $data
  495. * @param $is_add
  496. * @return array
  497. */
  498. public function productRule(&$data, $user, $is_add = true){
  499. if(empty($data['title'])) return [false,'产品名称不能为空'];
  500. if(empty($data['product_category_id'])) return [false,'产品分类不能为空'];
  501. if(empty($data['code'])) return [false,'产品编码不能为空'];
  502. if(empty($data['cost'])) return [false,'成本不能为空'];
  503. $res = $this->checkNumber($data['cost']);
  504. if(! $res) return [false,'成本请输入不超过两位小数并且大于0的数值'];
  505. if(empty($data['retail_price'])) return [false,'零售价不能为空'];
  506. $res = $this->checkNumber($data['retail_price']);
  507. if(! $res) return [false,'零售价格请输入不超过两位小数并且大于0的数值'];
  508. if(! empty($data['product_price'])){
  509. $map = BasicType::whereIn('id',array_column($data['product_price'],'basic_type_id'))
  510. ->pluck('title','id')
  511. ->toArray();
  512. foreach ($data['product_price'] as $value){
  513. if(! empty($value['price'])) {
  514. $tmp = $map[$value['basic_type_id']] ?? '';
  515. $res = $this->checkNumber($value['price']);
  516. if(! $res) return [false, $tmp . '请输入不超过两位小数并且大于0的数值'];
  517. }
  518. }
  519. }
  520. //所属部门 以及 顶级部门
  521. if(empty($data['depart_id'])) $data['depart_id'] = $this->getDepart($user);
  522. $data['top_depart_id'] = $user['depart_map'][$data['depart_id']] ?? 0;
  523. if($is_add){
  524. $bool = Product::whereRaw("(binary code = '{$data['code']}' OR title = '{$data['title']}')")
  525. ->where('del_time',0)
  526. ->exists();
  527. }else{
  528. if(empty($data['id'])) return [false,'ID不能为空'];
  529. $bool = Product::whereRaw("(binary code = '{$data['code']}' OR title = '{$data['title']}')")
  530. ->where('id','<>',$data['id'])
  531. ->where('del_time',0)
  532. ->exists();
  533. }
  534. if($bool) return [false,'产品名称或编码不能重复'];
  535. return [true, $data];
  536. }
  537. /**
  538. * 拼接数据
  539. * @param $data
  540. * @return array
  541. */
  542. public function fillData($data, $user){
  543. if(empty($data['data'])) return $data;
  544. $emp = Employee::whereIn('id',array_unique(array_column($data['data'],'crt_id')))
  545. ->pluck('emp_name','id')
  546. ->toArray();
  547. $category = ProductCategory::whereIn('id',array_unique(array_column($data['data'],'product_category_id')))
  548. ->pluck('title','id')
  549. ->toArray();
  550. $detail = ProductPriceDetail::where('del_time',0)
  551. ->whereIn('product_id',array_unique(array_column($data['data'],'id')))
  552. ->select('product_id','basic_type_id','price')
  553. ->get()->toArray();
  554. $basic_map = BasicType::whereIn('id',array_unique(array_merge_recursive(array_column($data['data'],'unit'),array_column($detail,'basic_type_id'))))
  555. ->pluck('title','id')
  556. ->toArray();
  557. $detail_map = [];
  558. foreach ($detail as $value){
  559. $detail_map[$value['product_id']][] = $value;
  560. }
  561. //是否总公司
  562. $is_main = $user['is_all_depart'];
  563. $top_depart = $user['depart_top'][0] ?? [];
  564. foreach ($data['data'] as $key => $value){
  565. $tmp = [];
  566. if(isset($detail_map[$value['id']])){
  567. $d = $detail_map[$value['id']];
  568. foreach ($d as $v){
  569. if(! $is_main && ($top_depart['basic_type_id'] != $v['basic_type_id'])) {
  570. $is_show = 0;
  571. }else{
  572. $is_show = 1;
  573. }
  574. if($top_depart['basic_type_id'] != $v['basic_type_id']) {
  575. $is_use = 0;
  576. }else{
  577. $is_use = 1;
  578. }
  579. $tmp[] = [
  580. 'basic_type_id' => $v['basic_type_id'],
  581. 'basic_type_title' => $basic_map[$v['basic_type_id']] ?? '',
  582. 'price' => $v['price'],
  583. 'is_show' => $is_show,
  584. 'is_use' => $is_use
  585. ];
  586. }
  587. }
  588. $data['data'][$key]['product_price'] = $tmp;
  589. $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
  590. $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
  591. $data['data'][$key]['product_category_name'] = $category[$value['product_category_id']] ?? '';
  592. $data['data'][$key]['state_name'] = Product::$state[$value['state']] ?? '';
  593. $data['data'][$key]['unit_name'] = $basic_map[$value['unit']] ?? '';
  594. }
  595. return $data;
  596. }
  597. //获取产品字典
  598. public function getProductDetail($product_id = []){
  599. if(empty($product_id)) return [];
  600. $pro = Product::whereIn('id', $product_id)->get()->toArray();
  601. return array_column($pro,null,'id');
  602. }
  603. }