143 lines
4.0 KiB
PHP
143 lines
4.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model;
|
|
|
|
use App\Constants\Common\OrderCode;
|
|
use Hyperf\Database\Concerns\BuildsQueries;
|
|
use Hyperf\Database\Model\Builder;
|
|
use Hyperf\Database\Model\Collection;
|
|
use Hyperf\DbConnection\Model\Model;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property string $order_sno
|
|
* @property int $user_id
|
|
* @property int $cycle_id
|
|
* @property int $site_id
|
|
* @property int $city_id
|
|
* @property int $kitchen_id
|
|
* @property int $coupon_id
|
|
* @property int $copies
|
|
* @property int $type
|
|
* @property string $total_price
|
|
* @property string $actual_price
|
|
* @property string $discount_price
|
|
* @property int $status
|
|
* @property int $is_refund_all
|
|
* @property string $cancel_time
|
|
* @property string $set_out_time
|
|
* @property string $delivery_time
|
|
* @property string $take_food_time
|
|
* @property string $finish_time
|
|
* @property string $pay_time
|
|
* @property string $order_json
|
|
* @property string $create_time
|
|
* @property string $update_time
|
|
*/
|
|
class Order extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*/
|
|
protected ?string $table = 'order';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*/
|
|
protected array $fillable = [];
|
|
|
|
protected array $guarded = [];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*/
|
|
protected array $casts = ['id' => 'integer', 'user_id' => 'integer', 'cycle_id' => 'integer', 'site_id' => 'integer', 'city_id' => 'integer', 'coupon_id' => 'integer', 'meal_copies' => 'integer', 'optional_copies' => 'integer', 'status' => 'integer', 'is_refund_all' => 'integer','kitchen_id' => 'integer'];
|
|
|
|
const string CREATED_AT = 'create_time';
|
|
|
|
const string UPDATED_AT = 'update_time';
|
|
|
|
/**
|
|
* @param int $id
|
|
* @return Order|Order[]|Collection|\Hyperf\Database\Model\Model|null
|
|
*/
|
|
public function getInfoById(int $id): array|Order|Collection|\Hyperf\Database\Model\Model|null
|
|
{
|
|
return $this->find($id);
|
|
}
|
|
|
|
/**
|
|
* @param string $orderSno
|
|
* @return \Hyperf\Database\Model\Model|Builder|BuildsQueries|null
|
|
*/
|
|
public function getInfoByOrderSno(string $orderSno): \Hyperf\Database\Model\Model|Builder|BuildsQueries|null
|
|
{
|
|
return $this->where('order_sno',$orderSno)->first();
|
|
}
|
|
|
|
/**
|
|
* @param array $orderIds
|
|
* @return int
|
|
*/
|
|
public function isCateringByOrderIds(array $orderIds): int
|
|
{
|
|
return $this->whereIn('id', $orderIds)->update([
|
|
'status' => OrderCode::PLAN
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @param int $cycleId
|
|
* @param int $kitchenId
|
|
* @return int|mixed|string
|
|
*/
|
|
public function getDiscountsByCycleIdAndKitchenId(int $cycleId, int $kitchenId): mixed
|
|
{
|
|
return $this->where('cycle_id',$cycleId)->where('kitchen_id',$kitchenId)->where('status',OrderCode::FINISH)->sum('discounts') ?? 0;
|
|
}
|
|
|
|
/**
|
|
* @param int $cycleId
|
|
* @param int $kitchenId
|
|
* @return int|mixed|string
|
|
*/
|
|
public function getNetSalesByCycleIdAndKitchenId(int $cycleId, int $kitchenId): mixed
|
|
{
|
|
return $this->where('cycle_id',$cycleId)->where('kitchen_id',$kitchenId)->where('status',OrderCode::FINISH)->sum('actual_price') ?? 0;
|
|
}
|
|
|
|
/**
|
|
* @param int $cycleId
|
|
* @param int $kitchenId
|
|
* @param int $type
|
|
* @return int
|
|
*/
|
|
public function getOrderNumberByCycleIdAndKitchenId(int $cycleId, int $kitchenId,int $type): int
|
|
{
|
|
return $this
|
|
->where('cycle_id',$cycleId)
|
|
->where('kitchen_id',$kitchenId)
|
|
->where('type',$type)
|
|
->where('status',OrderCode::FINISH)
|
|
->count() ?? 0;
|
|
}
|
|
|
|
/**
|
|
* @param int $cycleId
|
|
* @param int $kitchenId
|
|
* @param int $type
|
|
* @return int
|
|
*/
|
|
public function getCopiesByCycleIdAndKitchenId(int $cycleId, int $kitchenId,int $type): int
|
|
{
|
|
return $this
|
|
->where('cycle_id',$cycleId)
|
|
->where('kitchen_id',$kitchenId)
|
|
->where('type',$type)
|
|
->where('status',OrderCode::FINISH)
|
|
->sum('copies') ?? 0;
|
|
}
|
|
}
|