getMessage()); return false; } } /** * @notes 编辑采购订单 * @param array $params * @return bool * @author likeadmin * @date 2024/04/27 11:26 */ public static function edit(array $params): bool { Db::startTrans(); try { Opurchaseclass::where('id', $params['id'])->update([]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 删除采购订单 * @param array $params * @return bool * @author likeadmin * @date 2024/04/27 11:26 */ public static function delete(array $params): bool { return Opurchaseclass::destroy($params['id']); } /** * @notes 获取采购订单详情 * @param $params * @return array * @author likeadmin * @date 2024/04/27 11:26 */ public static function detail($params): array { $data = Opurchaseclass::findOrEmpty($params['id'])->toArray(); if ($data) { $data['goods_info'] = Opurchaseinfo::where('pid', $params['id'])->limit(25)->select()->each(function ($item) { $find=Goods::where('id', $item['goods'])->with('unitName')->find(); $item['goods_name']=$find['name']; $item['unit_name']=$find['unit_name']; // $sys_labels = Goods::where('id', $item['goods'])->value('sys_labels'); // $supplier_arr=[]; // if($sys_labels){ // $arr = explode(',', $sys_labels); // foreach ($arr as $k => $v) { // if($v>0){ // $supplier=Supplier::whereLike('sys_labels', "%," . $v . ",%")->field('id,mer_name')->find(); // if($supplier){ // $supplier_arr[]=$supplier; // } // } // } // } // $item['supplier'] = array_unique($supplier_arr); }); } return $data; } /** * @notes 推送供应商商品 * @param $params * @return bool * @date 2024/04/27 11:26 */ public static function createSupplierGoods($goods){ try{ $sys_labels = Goods::where('id', $goods['goods'])->value('sys_labels'); $supplier_arr=[]; $goods_offer=[]; if ($sys_labels) { $sys_labels_arr = explode(',', $sys_labels); foreach ($sys_labels_arr as $k => $v) { if ($v > 0) { $supplier = Supplier::whereLike('sys_labels', "%," . $v . ",%")->field('id,mer_name')->find(); if ($supplier) { $supplier_arr[] = $supplier; } } } } foreach($supplier_arr as $k=>$v){ $goods_offer[]=[ 'supplier_id'=>$v['supplier'], 'goods_id'=>$v['goods'], 'price'=>0, 'need_num' => $v['nums'] ]; } if($goods_offer){ $res=OpurchaseGoodsOffer::insertAll($goods_offer); if($res){ return true; } } }catch (\Exception $e){ self::setError($e->getMessage()); return false; } } /** * @notes 设置采纳商品 * @param $params * @return bool * @date 2024/04/27 11:26 */ public static function goodsOfferUpdate($params){ try{ OpurchaseGoodsOffer::where('id',$params)->update(['is_adopt'=>1]); return true; }catch (\Exception $e){ self::setError($e->getMessage()); return false; } } }