12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace app\admin\model;
- use support\Db;
- use support\Model;
- /**
- * 悦活套餐订单
- * Class Users
- * @package app\admin\model
- */
- class HomeOrder extends Model
- {
- /**
- *
- * The table associated with the model.
- *
- * @var string
- */
- protected $table = 'home_order';
- public $timestamps = false;
- /**
- * Notes:获取订单列表
- * @param string $keywords
- * @param int $page
- * @param int $limit
- * @return array
- * User: YCP
- * Date: 2022/11/2
- */
- public static function getOrderList(int $page, int $limit,$keywords)
- {
- $list = static::select('*')
- ->with(['User','HomeGoods'])
- ->when($keywords != '', function ($query) use ($keywords){
- $query->where('order_dno', 'like', '%' . $keywords . '%');
- })
- ->orderBy('order_create_time','DESC')
- ->forPage($page, $limit)
- ->get();
- $count = static::when($keywords != '', function ($query) use ($keywords){
- $query->where('order_dno', 'like', '%' . $keywords . '%');
- })
- ->count();
- return [$list, $count];
- }
-
- //关联用户
- public function User(){
- return $this->belongsTo(User::class,'order_user_id','user_id');
- }
- //关联项目
- public function HomeGoods(){
- return $this->belongsTo(HomeGoods::class,'order_goods_id','goods_id');
- }
- //时间格式
- public function getOrderCreateTimeAttribute($value)
- {
- return date('Y-m-d H:i:s', $value);
- }
- }
|