column('name','value'); foreach($quotation_detail as &$v){ $v['tax_inclusive_amount'] = $v['num'] * $v['tax_inclusive_price']; $v['tax_exclusive_amount'] = $v['num'] * $v['tax_inclusive_price'] * (1- $tax_rate_dict[$v['tax_rate']] / 100); } Db::startTrans(); try { $quotation = Quotation::create([ 'org_id' => $params['org_id'], 'dept_id' => $params['dept_id'], 'custom_id' => $params['custom_id'], 'code' => data_unique_code('报价单'), 'quotation_date' => !empty($params['quotation_date']) ? strtotime($params['quotation_date']) : 0, 'create_user' => $params['create_user'] ?? '', 'invoice_type' => $params['invoice_type'] ?? 0, 'freight' => $params['freight'], 'other_fee' => $params['other_fee'], 'customer_require' => $params['customer_require'] ?? '', 'remark' => $params['remark'] ?? '', 'annex' => $params['annex']? json_encode($params['annex']) : null, ]); foreach ($quotation_detail as $item) { QuotationDetail::create([ 'quotation_id' => $quotation->id, 'product_id' => $item['product_id'], 'num' => $item['num'], 'tax_rate' => $item['tax_rate'], 'tax_inclusive_price' => $item['tax_inclusive_price'], 'tax_inclusive_amount' => $item['tax_inclusive_price'] * $item['num'], 'tax_exclusive_amount' => $item['tax_inclusive_price'] * $item['num'] * (1- $tax_rate_dict[$item['tax_rate']] / 100), 'remark' => $item['remark'] ?? '' ]); } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 获取报价单详情 * @param $params * @return array * @author likeadmin * @date 2023/11/27 17:23 */ public static function detail($params): array { $data = Quotation::field('id,org_id,dept_id,custom_id,quotation_date,create_user,invoice_type,freight,other_fee,customer_require,remark,annex')->findOrEmpty($params['id']); $org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty(); $dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty(); $custom = Custom::field('name,master_name,master_phone')->where('id',$data['custom_id'])->findOrEmpty(); $data['org_name'] = $org['name']; $data['dept_name'] = $dept['name']; $data['custom_name'] = $custom['name']; $data['custom_master_name'] = $custom['master_name']; $data['custom_master_phone'] = $custom['master_phone']; $data['invoice_type_text'] = $data->invoice_type_text; $data['amount_including_tax'] = QuotationDetail::where('quotation_id',$data['id'])->sum('tax_inclusive_amount'); $data['total_amount'] = $data['amount_including_tax'] + $data['freight'] + $data['other_fee']; return $data->toArray(); } }