更新报价单模块

This commit is contained in:
yaooo 2023-12-09 11:49:01 +08:00
parent 7fe37f2b98
commit def064d645
4 changed files with 58 additions and 5 deletions

View File

@ -55,6 +55,7 @@ class QuotationLists extends BaseAdminDataLists implements ListsSearchInterface
public function lists(): array
{
return Quotation::where($this->searchWhere)
->with('product')
->field(['id', 'customer_id', 'quotation_date', 'contacts', 'contacts_phone', 'create_user', 'invoice_type', 'amount_including_tax', 'freight', 'other_fee', 'total_amount'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])

View File

@ -16,6 +16,7 @@ namespace app\adminapi\logic\quotation;
use app\common\model\quotation\Quotation;
use app\common\model\quotation\QuotationDetail;
use app\common\logic\BaseLogic;
use think\facade\Db;
@ -40,8 +41,9 @@ class QuotationLogic extends BaseLogic
{
Db::startTrans();
try {
Quotation::create([
$quotation = Quotation::create([
'customer_id' => $params['customer_id'],
'approve_id' => $params['approve_id'],
'quotation_date' => $params['quotation_date'],
'contacts' => $params['contacts'],
'contacts_phone' => $params['contacts_phone'],
@ -55,7 +57,16 @@ class QuotationLogic extends BaseLogic
'remark' => $params['remark'],
'annex' => $params['annex']
]);
foreach ($params['product'] as $item)
{
QuotationDetail::create([
'quotation_id' => $quotation->id,
'product_id' => $item['product_id'],
'product_num' => $item['product_num'],
'tax_rate' => $item['tax_rate'],
'remark' => $item['remark'] ?? ''
]);
}
Db::commit();
return true;
} catch (\Exception $e) {
@ -79,6 +90,7 @@ class QuotationLogic extends BaseLogic
try {
Quotation::where('id', $params['id'])->update([
'customer_id' => $params['customer_id'],
'approve_id' => $params['approve_id'],
'quotation_date' => $params['quotation_date'],
'contacts' => $params['contacts'],
'contacts_phone' => $params['contacts_phone'],
@ -92,7 +104,17 @@ class QuotationLogic extends BaseLogic
'remark' => $params['remark'],
'annex' => $params['annex']
]);
QuotationDetail::where('quotation_id', $params['id'])->delete();
foreach ($params['product'] as $item)
{
QuotationDetail::create([
'quotation_id' => $params['id'],
'product_id' => $item['product_id'],
'product_num' => $item['product_num'],
'tax_rate' => $item['tax_rate'],
'remark' => $item['remark'] ?? ''
]);
}
Db::commit();
return true;
} catch (\Exception $e) {
@ -112,6 +134,7 @@ class QuotationLogic extends BaseLogic
*/
public static function delete(array $params): bool
{
QuotationDetail::where('quotation_id', $params['id'])->update(['delete_time'=>time()]);
return Quotation::destroy($params['id']);
}
@ -125,6 +148,8 @@ class QuotationLogic extends BaseLogic
*/
public static function detail($params): array
{
return Quotation::findOrEmpty($params['id'])->toArray();
$quotation = Quotation::findOrEmpty($params['id']);
$quotation->product = $quotation->product;
return $quotation->toArray();
}
}

View File

@ -32,6 +32,7 @@ class QuotationValidate extends BaseValidate
*/
protected $rule = [
'id' => 'require',
'product' => 'require|array|checkProduct',
];
@ -64,7 +65,7 @@ class QuotationValidate extends BaseValidate
*/
public function sceneEdit()
{
return $this->only(['id']);
return $this->only(['id', 'product']);
}
@ -91,4 +92,19 @@ class QuotationValidate extends BaseValidate
return $this->only(['id']);
}
public function checkProduct($value, $rule, $data)
{
$firstData = $value[0];
if (empty($firstData['product_id'])) {
return '产品ID不能为空';
}
if (empty($firstData['product_num'])) {
return '产品数量不能为空!';
}
if (empty($firstData['tax_rate'])) {
return '产品税率不能为空!';
}
return true;
}
}

View File

@ -30,5 +30,16 @@ class Quotation extends BaseModel
protected $name = 'quotation';
protected $deleteTime = 'delete_time';
/**
* @notes 关联device
* @return \think\model\relation\HasOne
* @author likeadmin
* @date 2023/11/24 16:34
*/
public function product()
{
return $this->hasMany(\app\common\model\quotation\QuotationDetail::class, 'quotation_id', 'id');
}
}