|
@@ -5,17 +5,20 @@ namespace app\common\model;
|
|
|
use app\service\pay_user\PayUser;
|
|
|
use think\db\Query;
|
|
|
use think\Model;
|
|
|
+use think\model\Collection;
|
|
|
use traits\model\SoftDelete;
|
|
|
|
|
|
|
|
|
*@property array send_detail 运送详情
|
|
|
*@property float cal_refund 退款手续费
|
|
|
*@property float refund_money 退款金额
|
|
|
- *@property SenderOrder[] currentSenderOrder
|
|
|
+ *@property Collection currentSenderOrder
|
|
|
*@property float settle_amount
|
|
|
*@property array senders
|
|
|
*@property array settle_info
|
|
|
*@property float profit
|
|
|
+ *@property boolean is_same_city
|
|
|
+ *@property boolean is_same_user
|
|
|
*@method Query|self expired()
|
|
|
*/
|
|
|
class UserOrder extends Model
|
|
@@ -213,6 +216,9 @@ class UserOrder extends Model
|
|
|
if($data['status']==1){
|
|
|
$this['status']=self::STATUS_SET;
|
|
|
foreach ($this->currentSenderOrder as $senderOrder){
|
|
|
+ if(is_null($senderOrder['fee_total'])){
|
|
|
+ throw_user('有配送员尚未申请结算,请稍后再试');
|
|
|
+ }
|
|
|
PayUser::getClass()->payment($senderOrder['fee_total'],$senderOrder['user'],MoneyLog::TYPE_SETTLE,"订单[{$this['no']}]结算",['order_id'=>$this['id']]);
|
|
|
}
|
|
|
|
|
@@ -300,13 +306,19 @@ class UserOrder extends Model
|
|
|
|
|
|
public function checkGet(User $user){
|
|
|
if(count($this->currentSenderOrder)>1){
|
|
|
- throw_user('订单已被接单,您暂时无法接单');
|
|
|
+ throw_user('订单已被接单,您暂时无法接单(1)');
|
|
|
}
|
|
|
$type=$user->getSendType($this);
|
|
|
+
|
|
|
+ if($this->is_same_city && $this->currentSenderOrder->count()===1){
|
|
|
+ $typeArr=$this->currentSenderOrder->column('type');
|
|
|
+ $array = array_diff(User::$sendType, $typeArr);
|
|
|
+ return end($array);
|
|
|
+ }
|
|
|
if($user->isSendGet($type)) {
|
|
|
$can = $this['status'] == self::STATUS_WAIT_GET;
|
|
|
if (!$can) {
|
|
|
- throw_user("订单已被接单,您暂时无法接单");
|
|
|
+ throw_user("订单已被接单,您暂时无法接单(2)");
|
|
|
}
|
|
|
}
|
|
|
return $type;
|
|
@@ -330,14 +342,12 @@ class UserOrder extends Model
|
|
|
if(!$sender_order){
|
|
|
throw_user('保存配送员订单失败');
|
|
|
}
|
|
|
- if(!$this->save()){
|
|
|
- throw_user('保存失败');
|
|
|
- }
|
|
|
+ $this->save();
|
|
|
}
|
|
|
|
|
|
public function updateStatus($status,User $user){
|
|
|
if(!$status){
|
|
|
- return;
|
|
|
+ throw_user('状态有误');
|
|
|
}
|
|
|
$this->refunding();
|
|
|
$senderS=[
|
|
@@ -347,20 +357,24 @@ class UserOrder extends Model
|
|
|
$recS=[
|
|
|
self::STATUS_GIVING=>self::STATUS_GIVED,
|
|
|
];
|
|
|
- $arr=array_merge($senderS,$recS);
|
|
|
+ $arr=$senderS+$recS;
|
|
|
if($this['status']!=$status){
|
|
|
throw_user('状态'.self::$statusList[$this['status']].'有误');
|
|
|
}
|
|
|
- $type=$user->getSendType($this);
|
|
|
- if($user->isSendGet($type) && !isset($senderS[$status])){
|
|
|
- throw_user('您是取宠人,无法更新状态'.self::$statusList[$status]);
|
|
|
- }elseif($user->isSendSend($type) && !isset($recS[$status])){
|
|
|
- throw_user('您是送宠人,无法更新状态'.self::$statusList[$status]);
|
|
|
+ if(!$this->is_same_user) {
|
|
|
+ $type = $user->getSendType($this);
|
|
|
+ if ($user->isSendGet($type) && !isset($senderS[$status])) {
|
|
|
+ throw_user('您是取宠人,无法更新状态' . self::$statusList[$status]);
|
|
|
+ } elseif ($user->isSendSend($type) && !isset($recS[$status])) {
|
|
|
+ throw_user('您是送宠人,无法更新状态' . self::$statusList[$status]);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
$this['status']=$arr[$status];
|
|
|
if(!$this->save()){
|
|
|
throw_user('更新失败');
|
|
|
}
|
|
|
+ return $this['status'];
|
|
|
}
|
|
|
|
|
|
public function scopeRunning(Query $query){
|
|
@@ -413,6 +427,14 @@ class UserOrder extends Model
|
|
|
public function getProfitAttr($v,$data){
|
|
|
return bcsub($this['real_amount'],$this->settle_info['fee_total']);
|
|
|
}
|
|
|
+
|
|
|
+ public function getIsSameCityAttr(){
|
|
|
+ return $this['from_city']==$this['to_city'];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getIsSameUserAttr(){
|
|
|
+ return $this->currentSenderOrder->count()==2 && count(array_unique($this->currentSenderOrder->column('user_id')))==1;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|