123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- <?php
- namespace App\Models;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Validator;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Database\Eloquent\SoftDeletes;
- class Order extends Model
- {
- use SoftDeletes;
- protected $table='order';
- protected $fillable = ['agent_id','user_id','ordersn','price',
- 'address_id','desc','status','is_turn','turn_is','breakup_id',
- 'manual_ordersn','is_manual','original_ordersn'];
- private static $rules=[
- 'mobile'=>[
- 'required',
- 'regex:/^1[345789][0-9]{9}$/'
- ],
- 'name'=>'required',
- 'address'=>'required',
- ];
- private static $validate = [
- //提示信息
- 'message' => [
- 'mobile.required'=>'手机号不能为空.',
- 'mobile.regex'=>'手机号格式有误.',
- 'name.required'=>'名称不能为空.',
- 'address.required'=>'地址不能为空.',
- ]
- ];
- public function validator($data)
- {
- return Validator::make(
- $data,
- self::$rules,
- self::$validate['message']
- );
- }
- //生成订单号
- private function createOrderNo($id){
- $ordersn=time().str_pad($id, 6, '0', STR_PAD_LEFT).mt_rand(1000,9999);
- return $ordersn;
- }
- //添加手动订单
- public function createManualOrder($user,$addressId,$desc){
- $data['user_id']=$user->id;
- $data['sender_id']='1';//公司发货(发货人id)
- $data['admin_id']=Auth::user()->id;
- $data['manualsn']=$this->createOrderNo($user->id);
- $data['address_id']=$addressId?$addressId:0;
- $data['desc']=$desc;
- $data['status']=1;//已发货
- $manOrder=OrderManual::create($data);//创建手动订单
- $result['manOrderSn']=$data['manualsn'];
- $result['manOrderId']=$manOrder->id;
- return $result;
- }
- //添加订单信息
- public function createOrder($manOrder,$user,$crown){
- $data['agent_id']=$crown['agent_id'];
- $data['user_id']=$crown['user_id'];
- $data['ordersn']=$this->createOrderNo($user->id);
- $data['price']=$crown['price'];
- $data['address_id']=$crown['address_id'];
- $data['desc']=$crown['desc'];
- $data['status']='2';//待收货
- $data['is_turn']='0';
- $data['turn_is']='0';
- $data['breakup_id']=NULL;
- $data['original_ordersn']='';
- $data['manual_ordersn']=$manOrder['manOrderSn'];
- $data['is_manual']='1';
- $order=Order::create($data);//添加订单信息
- return $order->id;
- }
- //添加订单商品信息
- public function createOrderGoods($val,$v,$user,$orderId,$manOrder){
- $orderskuprice=GoodsSkuPrice::where('goods_id',$val['goodId'])
- ->where('sku_id',$v['id'])
- ->where('user_level',$user->level)->first();
- $data['order_id']=$orderId;
- $data['breakup_id']='';
- $data['manual_id']=12;//$manOrder['manOrderId'];
- $data['goods_id']=$val['goodId'];
- $data['sku_id']=$v['id'];
- $data['price']=$orderskuprice->price;
- $data['num']=$v['num'];
- $data['totalprice']=$orderskuprice->price*$v['num'];
- OrderGoods::create($data);
- }
- //添加地址
- public function createAddressInfo($input){
- $data['user_id']='1';//公司id
- $data['username']=$input['name'];
- $data['mobile']=$input['mobile'];
- $data['address']=$input['address'];
- $result=Address::create($data);
- return $result->id;
- }
- public function orderbreakup()
- {
- return $this->hasMany('App\OrderBreakup','ordersn','ordersn');
- }
- public function ordergoods()
- {
- return $this->hasMany('App\Models\OrderGoods','order_id');
- }
- public function user()
- {
- return $this->belongsTo('App\Models\User','user_id')->withTrashed();
- }
- public function agent()
- {
- return $this->belongsTo('App\Models\User','agent_id')->withTrashed();
- }
- public function address()
- {
- return $this->belongsTo('App\Models\Address','address_id');
- }
- //订单审核
- public static function order_audit($order_id,$order,$name){
- //修改订单
- Ordertest::where('id',$order_id)->update(['status'=>1,'is_back'=>0]);
- //记录操作日志
- Orderlog::create([
- 'order_id'=>$order_id,
- 'user_id'=>$order->user_id,
- 'log_name'=>$name,
- 'log_title'=>'订货单订单审核',
- 'log_text'=>'订货单已通过订单审核'
- ]);
- }
- //财务审核
- public static function financial_audit($order_id,$order,$name){
- //修改订单
- Ordertest::where('id',$order_id)->update(['status'=>2,'is_back'=>0]);
- //记录操作日志
- Orderlog::create([
- 'order_id'=>$order_id,
- 'user_id'=>$order->user_id,
- 'log_name'=>$name,
- 'log_title'=>'订货单财务审核',
- 'log_text'=>'订货单已通过财务审核'
- ]);
- }
- //发货审核
- public static function send_audit($order_id,$order,$name){
- //修改订单
- Ordertest::where('id',$order_id)->update(['status'=>3,'is_back'=>0]);
- //记录操作日志
- Orderlog::create([
- 'order_id'=>$order_id,
- 'user_id'=>$order->user_id,
- 'log_name'=>$name,
- 'log_title'=>'订货单发货审核',
- 'log_text'=>'订货单已通过发货审核'
- ]);
- }
- //订单回退
- public static function order_back(){
- }
- //财务回退
- public static function financial_back($order_id,$order,$name,$remark){
- //修改订单
- Ordertest::where('id',$order_id)->update(['status'=>0,'is_back'=>1]);
- //记录操作日志
- Orderlog::create([
- 'order_id'=>$order_id,
- 'user_id'=>$order->user_id,
- 'log_name'=>$name,
- 'log_title'=>'订货单财务审核',
- 'log_text'=>'订货单未通过财务审核,退回重审'
- ]);
- //备注
- if($remark){
- OrderRemark::create([
- 'order_id'=>$order_id,
- 'name'=>$name,
- 'level'=>'',
- 'type'=>2,
- 'remark'=>$remark
- ]);
- }
- }
- //发货回退
- public static function send_back($order_id,$order,$name,$remark){
- //修改订单
- Ordertest::where('id',$order_id)->update(['status'=>1,'is_back'=>1]);
- //记录操作日志
- Orderlog::create([
- 'order_id'=>$order_id,
- 'user_id'=>$order->user_id,
- 'log_name'=>$name,
- 'log_title'=>'订货单发货审核',
- 'log_text'=>'订货单未通过发货审核,退回重审'
- ]);
- //备注
- if($remark){
- OrderRemark::create([
- 'order_id'=>$order_id,
- 'name'=>$name,
- 'level'=>'',
- 'type'=>2,
- 'remark'=>$remark
- ]);
- }
- }
- //收货回退
- public static function receive_back($order_id,$order,$name,$remark){
- //修改订单
- Ordertest::where('id',$order_id)->update(['status'=>2,'is_back'=>1,'receive_time'=>NULL,'track_time'=>NULL]);
- //记录操作日志
- Orderlog::create([
- 'order_id'=>$order_id,
- 'user_id'=>$order->user_id,
- 'log_name'=>$name,
- 'log_title'=>'订货单发货后审核',
- 'log_text'=>'订货单发货后,退回重审'
- ]);
- //备注
- if($remark){
- OrderRemark::create([
- 'order_id'=>$order_id,
- 'name'=>$name,
- 'level'=>'',
- 'type'=>2,
- 'remark'=>$remark
- ]);
- }
- }
- }
|