110 lines
2.8 KiB
PHP
110 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* Author:
|
|
* Date: 2018/9/19
|
|
* Time: 下午3:41
|
|
*/
|
|
|
|
namespace app\common\models\order;
|
|
|
|
|
|
use app\common\models\BaseModel;
|
|
use app\common\models\Member;
|
|
use app\common\models\OrderGoods;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Yunshop\StoreCashier\common\models\CashierOrder;
|
|
use Yunshop\StoreCashier\common\models\StoreOrder;
|
|
use Yunshop\Supplier\common\models\SupplierOrder;
|
|
|
|
class OrderPluginBonus extends BaseModel
|
|
{
|
|
public $table = 'yz_order_plugin_bonus';
|
|
public $timestamps = true;
|
|
protected $guarded = [''];
|
|
protected $casts = [
|
|
'ids' => 'json'
|
|
];
|
|
protected $appends = [
|
|
'info'
|
|
];
|
|
|
|
public function scopeSearch($query,$search)
|
|
{
|
|
$query->uniacid();
|
|
if ($search['member_id']) {
|
|
$query->where('member_id', $search['member_id']);
|
|
}
|
|
if ($search['order_sn']) {
|
|
$query->where('content', $search['order_sn']);
|
|
}
|
|
if ($search['is_time']) {
|
|
$time = [strtotime($search['start_time']),strtotime($search['end_time'])];
|
|
$query->whereBetween('created_at', $time);
|
|
}
|
|
if ($search['member']) {
|
|
$query->whereHas('hasOneMember',function ($q)use ($search) {
|
|
$q->searchLike($search['member_id']);
|
|
});
|
|
}
|
|
return $query; // TODO: Change the autogenerated stub
|
|
}
|
|
|
|
public static function addRow($row)
|
|
{
|
|
$model = new self();
|
|
$model->fill($row);
|
|
$model->save();
|
|
return $model;
|
|
}
|
|
|
|
public static function updateRow($row)
|
|
{
|
|
$model = self::where('order_id', $row['order_id'])->where('code',$row['code']);
|
|
$model->update($row);
|
|
return $model;
|
|
}
|
|
|
|
public static function updateStatus($order_id)
|
|
{
|
|
$model = self::where('order_id', $order_id)->update(['status' => 1]);
|
|
return $model;
|
|
}
|
|
|
|
public static function getInfoByOrderId($order_id)
|
|
{
|
|
return self::select()->where('order_id', $order_id);
|
|
}
|
|
|
|
public function getInfoAttribute()
|
|
{
|
|
$info = DB::table($this->table_name)->select()
|
|
->whereIn('id', $this->ids)
|
|
->get();
|
|
return $info;
|
|
}
|
|
|
|
public function hasOneOrderGoods()
|
|
{
|
|
return $this->hasOne(OrderGoods::class,'order_id','order_id');
|
|
}
|
|
|
|
public function hasOneCashierOrder()
|
|
{
|
|
return $this->hasOne(CashierOrder::class,'order_id','order_id');
|
|
}
|
|
|
|
public function hasOneStoreOrder()
|
|
{
|
|
return $this->hasOne(StoreOrder::class,'order_id','order_id');
|
|
}
|
|
|
|
public function hasOneSupplierOrder()
|
|
{
|
|
return $this->hasOne(SupplierOrder::class,'order_id','order_id');
|
|
}
|
|
public function hasOneMember()
|
|
{
|
|
return $this->hasOne(Member::class,'uid','member_id');
|
|
}
|
|
} |