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 { $id=$params['id']; $data = Opurchaseclass::findOrEmpty($params['id'])->toArray(); if ($data) { $data['goods_info'] = Opurchaseinfo::where('pid', $params['id'])->limit(25)->select()->each(function ($item)use($id) { $find = Goods::where('id', $item['goods'])->with('unitName')->find(); if ($find) { $item['goods_name'] = $find['name']; $item['unit_name'] = $find['unit_name']; } $where=[ 'goods_id'=>$item['goods'], 'order_id'=>$id, 'is_adopt'=>1 ]; $item['nums_count']=OpurchaseGoodsOffer::where($where)->sum('nums'); }); $data['merchant_name'] = Merchant::where('mer_id', $data['merchant'])->value('mer_name'); } return $data; } /** * @notes 采购订单子订单详情 * @param $id * @return array * @author likeadmin * @date 2024/04/27 11:26 */ public static function sub_detail($id, $page_no): array { $order_arr = Opurchaseclass::where('id', $id)->value('order_arr'); $data = []; if ($order_arr) { $order_arr = explode(',', $order_arr); $order_arr_count = count($order_arr); $offset = ($page_no - 1) * $order_arr_count; $paged_items = array_slice($order_arr, $offset, $order_arr_count); if (!$paged_items) { return []; } $list = Cashierclass::whereIn('id', $order_arr)->select()?->toArray(); $data['count'] = $order_arr_count; $data['lists'] = $list; $data['page_no'] = $page_no; $data['page_siz'] = 15; } 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()); Log::error('添加采购订单报价失败:' . $e->getMessage()); return false; } } /** * @notes 设置采纳商品 * @param $params * @return bool * @date 2024/04/27 11:26 */ public static function goodsOfferUpdate($id,$type=0,$notes='',$nums=0) { try { $find=OpurchaseGoodsOffer::where('id', $id)->find(); if($type==0){ if($find &&$find['price']==0){ self::setError('报价未设置'); return false; } $find->is_adopt=1; }else{ $find->is_storage=1; $find->notes=$notes; $find->before_nums=$find->nums; $find->nums=$nums; } $res= $find->save(); if($res){ return true; } return false; } catch (\Exception $e) { self::setError($e->getMessage()); return false; } } }