|
@@ -5,6 +5,7 @@ namespace App\Service;
|
|
use App\Model\BasicType;
|
|
use App\Model\BasicType;
|
|
use App\Model\Customer;
|
|
use App\Model\Customer;
|
|
use App\Model\Employee;
|
|
use App\Model\Employee;
|
|
|
|
+use App\Model\Product;
|
|
use App\Model\SalesOrder;
|
|
use App\Model\SalesOrder;
|
|
use App\Model\SalesOrderInfo;
|
|
use App\Model\SalesOrderInfo;
|
|
use App\Model\SalesOrderProductInfo;
|
|
use App\Model\SalesOrderProductInfo;
|
|
@@ -13,7 +14,7 @@ use Illuminate\Support\Facades\DB;
|
|
class SalesOrderService extends Service
|
|
class SalesOrderService extends Service
|
|
{
|
|
{
|
|
public function salesOrderEdit($data,$user){
|
|
public function salesOrderEdit($data,$user){
|
|
- list($status,$msg) = $this->salesOrderRule($data,false);
|
|
|
|
|
|
+ list($status,$msg) = $this->salesOrderRule($data, $user, false);
|
|
if(!$status) return [$status,$msg];
|
|
if(!$status) return [$status,$msg];
|
|
|
|
|
|
try {
|
|
try {
|
|
@@ -50,6 +51,7 @@ class SalesOrderService extends Service
|
|
$model->color = $data['color'] ?? '';
|
|
$model->color = $data['color'] ?? '';
|
|
$model->original_set = $data['original_set'] ?? '';
|
|
$model->original_set = $data['original_set'] ?? '';
|
|
$model->processing = $data['processing'] ?? '';
|
|
$model->processing = $data['processing'] ?? '';
|
|
|
|
+ $model->depart_id = $data['depart_id'] ?? 0;
|
|
$model->save();
|
|
$model->save();
|
|
$time = time();
|
|
$time = time();
|
|
|
|
|
|
@@ -124,7 +126,7 @@ class SalesOrderService extends Service
|
|
}
|
|
}
|
|
|
|
|
|
public function salesOrderAdd($data,$user){
|
|
public function salesOrderAdd($data,$user){
|
|
- list($status,$msg) = $this->salesOrderRule($data);
|
|
|
|
|
|
+ list($status,$msg) = $this->salesOrderRule($data,$user);
|
|
if(!$status) return [$status,$msg];
|
|
if(!$status) return [$status,$msg];
|
|
|
|
|
|
try {
|
|
try {
|
|
@@ -161,6 +163,7 @@ class SalesOrderService extends Service
|
|
$model->color = $data['color'] ?? '';
|
|
$model->color = $data['color'] ?? '';
|
|
$model->original_set = $data['original_set'] ?? '';
|
|
$model->original_set = $data['original_set'] ?? '';
|
|
$model->processing = $data['processing'] ?? '';
|
|
$model->processing = $data['processing'] ?? '';
|
|
|
|
+ $model->depart_id = $data['depart_id'] ?? 0;
|
|
$model->crt_id = $user['id'];
|
|
$model->crt_id = $user['id'];
|
|
$model->save();
|
|
$model->save();
|
|
$time = time();
|
|
$time = time();
|
|
@@ -311,12 +314,23 @@ class SalesOrderService extends Service
|
|
->where('sales_order_id',$sales['id'])
|
|
->where('sales_order_id',$sales['id'])
|
|
->select('id','sales_order_id','product_id','mark','price','number')
|
|
->select('id','sales_order_id','product_id','mark','price','number')
|
|
->get()->toArray();
|
|
->get()->toArray();
|
|
|
|
+ $pro = Product::whereIn('id',array_column($sales_p_info,'product_id'))
|
|
|
|
+ ->select('bar_code','code','cost','depart_price','size','title','id')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+ $pro = array_column($pro,null,'id');
|
|
foreach ($sales_p_info as $value){
|
|
foreach ($sales_p_info as $value){
|
|
|
|
+ $p = $pro[$value['product_id']] ?? [];
|
|
$sales['product'][] = [
|
|
$sales['product'][] = [
|
|
'product_id' => $value['product_id'],
|
|
'product_id' => $value['product_id'],
|
|
'mark' => $value['mark'],
|
|
'mark' => $value['mark'],
|
|
'retail_price' => $value['price'],
|
|
'retail_price' => $value['price'],
|
|
'number' => $value['number'],
|
|
'number' => $value['number'],
|
|
|
|
+ 'bar_code' => $p['bar_code'] ?? '',
|
|
|
|
+ 'code' => $p['code'] ?? '',
|
|
|
|
+ 'cost' => $p['cost'] ?? 0,
|
|
|
|
+ 'depart_price' => $p['depart_price'] ?? 0,
|
|
|
|
+ 'size' => $p['size'] ?? '',
|
|
|
|
+ 'title' => $p['title'] ?? '',
|
|
];
|
|
];
|
|
}
|
|
}
|
|
$sales['crt_name'] = $emp_map[$sales['crt_id']] ?? '';
|
|
$sales['crt_name'] = $emp_map[$sales['crt_id']] ?? '';
|
|
@@ -326,7 +340,8 @@ class SalesOrderService extends Service
|
|
}
|
|
}
|
|
|
|
|
|
public function salesOrderList($data,$user){
|
|
public function salesOrderList($data,$user){
|
|
- $model = SalesOrder::where('del_time',0)
|
|
|
|
|
|
+ $model = new SalesOrder(['userData' => $user]);
|
|
|
|
+ $model = $model->where('del_time',0)
|
|
->select('title','id','model_type','order_number','selling_price','vin_no','car_type','order_type','deal_type','customer_id','sign_time','contract_state','crt_id','crt_time','mark','product_total','rate','construction_time','handover_time','expire_time','other_fee','discount_fee','contract_fee','contract_type','pay_way','send_state','logistics_company','logistics_number','car_type','year','mileage','color','original_set','processing','state')
|
|
->select('title','id','model_type','order_number','selling_price','vin_no','car_type','order_type','deal_type','customer_id','sign_time','contract_state','crt_id','crt_time','mark','product_total','rate','construction_time','handover_time','expire_time','other_fee','discount_fee','contract_fee','contract_type','pay_way','send_state','logistics_company','logistics_number','car_type','year','mileage','color','original_set','processing','state')
|
|
->orderby('id', 'desc');
|
|
->orderby('id', 'desc');
|
|
|
|
|
|
@@ -352,7 +367,7 @@ class SalesOrderService extends Service
|
|
return [true, $list];
|
|
return [true, $list];
|
|
}
|
|
}
|
|
|
|
|
|
- public function salesOrderRule(&$data, $is_add = true){
|
|
|
|
|
|
+ public function salesOrderRule(&$data, $user, $is_add = true){
|
|
if(empty($data['model_type'])) return [false,'订单模板类型不能为空'];
|
|
if(empty($data['model_type'])) return [false,'订单模板类型不能为空'];
|
|
if(! in_array($data['model_type'],SalesOrder::$model_type)) return [false,'订单模板类型错误'];
|
|
if(! in_array($data['model_type'],SalesOrder::$model_type)) return [false,'订单模板类型错误'];
|
|
if(empty($data['order_number'])) return [false,'合同编号不能为空'];
|
|
if(empty($data['order_number'])) return [false,'合同编号不能为空'];
|
|
@@ -376,7 +391,6 @@ class SalesOrderService extends Service
|
|
if(empty($data['contract_fee'])) return [false,'合同金额不能为空'];
|
|
if(empty($data['contract_fee'])) return [false,'合同金额不能为空'];
|
|
$res = $this->checkNumber($data['contract_fee']);
|
|
$res = $this->checkNumber($data['contract_fee']);
|
|
if(! $res) return [false, '合同金额请输入不超过两位小数并且大于0的数值'];
|
|
if(! $res) return [false, '合同金额请输入不超过两位小数并且大于0的数值'];
|
|
-
|
|
|
|
if(! empty($data['rate'])){
|
|
if(! empty($data['rate'])){
|
|
$res = $this->checkNumber($data['rate']);
|
|
$res = $this->checkNumber($data['rate']);
|
|
if(! $res) return [false, '整单扣除率请输入不超过两位小数并且大于0的数值'];
|
|
if(! $res) return [false, '整单扣除率请输入不超过两位小数并且大于0的数值'];
|
|
@@ -389,6 +403,7 @@ class SalesOrderService extends Service
|
|
$res = $this->checkNumber($data['discount_fee']);
|
|
$res = $this->checkNumber($data['discount_fee']);
|
|
if(! $res) return [false, '优惠金额请输入不超过两位小数并且大于0的数值'];
|
|
if(! $res) return [false, '优惠金额请输入不超过两位小数并且大于0的数值'];
|
|
}
|
|
}
|
|
|
|
+ if(empty($data['depart_id'])) $data['depart_id'] = $this->getDepart($user);
|
|
|
|
|
|
if($data['model_type'] == SalesOrder::Model_type_one){
|
|
if($data['model_type'] == SalesOrder::Model_type_one){
|
|
if(empty($data['order_type'])) return [false,'订单类型不能为空'];
|
|
if(empty($data['order_type'])) return [false,'订单类型不能为空'];
|