ProductService.php 25 KB

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