更新报价单模块
This commit is contained in:
parent
7fe37f2b98
commit
def064d645
@ -55,6 +55,7 @@ class QuotationLists extends BaseAdminDataLists implements ListsSearchInterface
|
|||||||
public function lists(): array
|
public function lists(): array
|
||||||
{
|
{
|
||||||
return Quotation::where($this->searchWhere)
|
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'])
|
->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)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['id' => 'desc'])
|
->order(['id' => 'desc'])
|
||||||
|
@ -16,6 +16,7 @@ namespace app\adminapi\logic\quotation;
|
|||||||
|
|
||||||
|
|
||||||
use app\common\model\quotation\Quotation;
|
use app\common\model\quotation\Quotation;
|
||||||
|
use app\common\model\quotation\QuotationDetail;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
|
||||||
@ -40,8 +41,9 @@ class QuotationLogic extends BaseLogic
|
|||||||
{
|
{
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
Quotation::create([
|
$quotation = Quotation::create([
|
||||||
'customer_id' => $params['customer_id'],
|
'customer_id' => $params['customer_id'],
|
||||||
|
'approve_id' => $params['approve_id'],
|
||||||
'quotation_date' => $params['quotation_date'],
|
'quotation_date' => $params['quotation_date'],
|
||||||
'contacts' => $params['contacts'],
|
'contacts' => $params['contacts'],
|
||||||
'contacts_phone' => $params['contacts_phone'],
|
'contacts_phone' => $params['contacts_phone'],
|
||||||
@ -55,7 +57,16 @@ class QuotationLogic extends BaseLogic
|
|||||||
'remark' => $params['remark'],
|
'remark' => $params['remark'],
|
||||||
'annex' => $params['annex']
|
'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();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -79,6 +90,7 @@ class QuotationLogic extends BaseLogic
|
|||||||
try {
|
try {
|
||||||
Quotation::where('id', $params['id'])->update([
|
Quotation::where('id', $params['id'])->update([
|
||||||
'customer_id' => $params['customer_id'],
|
'customer_id' => $params['customer_id'],
|
||||||
|
'approve_id' => $params['approve_id'],
|
||||||
'quotation_date' => $params['quotation_date'],
|
'quotation_date' => $params['quotation_date'],
|
||||||
'contacts' => $params['contacts'],
|
'contacts' => $params['contacts'],
|
||||||
'contacts_phone' => $params['contacts_phone'],
|
'contacts_phone' => $params['contacts_phone'],
|
||||||
@ -92,7 +104,17 @@ class QuotationLogic extends BaseLogic
|
|||||||
'remark' => $params['remark'],
|
'remark' => $params['remark'],
|
||||||
'annex' => $params['annex']
|
'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();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -112,6 +134,7 @@ class QuotationLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function delete(array $params): bool
|
public static function delete(array $params): bool
|
||||||
{
|
{
|
||||||
|
QuotationDetail::where('quotation_id', $params['id'])->update(['delete_time'=>time()]);
|
||||||
return Quotation::destroy($params['id']);
|
return Quotation::destroy($params['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,6 +148,8 @@ class QuotationLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function detail($params): array
|
public static function detail($params): array
|
||||||
{
|
{
|
||||||
return Quotation::findOrEmpty($params['id'])->toArray();
|
$quotation = Quotation::findOrEmpty($params['id']);
|
||||||
|
$quotation->product = $quotation->product;
|
||||||
|
return $quotation->toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -32,6 +32,7 @@ class QuotationValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
'id' => 'require',
|
'id' => 'require',
|
||||||
|
'product' => 'require|array|checkProduct',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
@ -64,7 +65,7 @@ class QuotationValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
public function sceneEdit()
|
public function sceneEdit()
|
||||||
{
|
{
|
||||||
return $this->only(['id']);
|
return $this->only(['id', 'product']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -91,4 +92,19 @@ class QuotationValidate extends BaseValidate
|
|||||||
return $this->only(['id']);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -30,5 +30,16 @@ class Quotation extends BaseModel
|
|||||||
protected $name = 'quotation';
|
protected $name = 'quotation';
|
||||||
protected $deleteTime = 'delete_time';
|
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');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user