You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.3 KiB
74 lines
2.3 KiB
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Admin\Common\Rpc;
|
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class ImsCjdcOrderMain extends Model
|
|
{
|
|
use HasDateTimeFormatter;
|
|
//protected $table = 'ims_cjdc_order_main';
|
|
protected $table = 'lanzu_order_main';
|
|
public $timestamps = false;
|
|
|
|
public function imsCjdcUser()
|
|
{
|
|
return $this->hasOne('\App\Models\ImsCjdcUser','id','user_id');
|
|
}
|
|
|
|
public function market()
|
|
{
|
|
return $this->hasOne('\App\Models\ImsCjdcMarket','id','market_id');
|
|
}
|
|
|
|
/**
|
|
* 变更订单状态,
|
|
* @param $oid //主订单id
|
|
* @param $state //订单状态
|
|
*/
|
|
public function modifyState($oid,$state)
|
|
{
|
|
$where = [];
|
|
$where['state'] = $state;
|
|
$where['updated_at'] = time();
|
|
if ($state==3) {
|
|
$where['receive_time'] = time();
|
|
}elseif ($state==4){
|
|
$where['complete_time'] = time();
|
|
}elseif ($state==6){
|
|
$where['cancel_time'] = time();
|
|
}
|
|
|
|
return self::where('id',$oid)->update($where);
|
|
|
|
}
|
|
|
|
public function updateShippingType($oid,$type)
|
|
{
|
|
return self::where('id',$oid)->update(['shipping_type'=>$type]);
|
|
}
|
|
|
|
public static function getOrderData($oid)
|
|
{
|
|
$order = ImsCjdcOrderMain::where('id', $oid)->first()->toArray();
|
|
$order['created_at'] = date('Y-m-d H:i:s', $order['created_at']);
|
|
$order['updated_at'] = $order['updated_at'] ? date('Y-m-d H:i:s', $order['updated_at']) : null;
|
|
$order['pay_type'] = config('order.pay_type')[$order['pay_type']];
|
|
$order['shipping_type'] = config('order.shipping_type')[$order['shipping_type']];
|
|
$order['horseman_name'] = LanzuServiceHorseman::getName($order['horseman_id']);
|
|
|
|
//获取市场经纬度
|
|
//$market = LanzuMarket::where('id',$order['market_id'])->first()->toArray();
|
|
//$order['distance'] = Rpc::getDistance($market['lng'],$market['lat'],$order['lng'],$order['lat'])['result'];
|
|
if ($order['delivery_distance']>1000){
|
|
$order['delivery_distance']= number_format(($order['delivery_distance']/1000), 1) .'km';
|
|
}else{
|
|
$order['delivery_distance'].= '米';
|
|
}
|
|
return $order;
|
|
}
|
|
}
|