Files
hyperf_service/app/Model/OrderGood.php
2025-04-09 15:31:11 +08:00

82 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Model;
use App\Constants\Common\OrderCode;
use Hyperf\DbConnection\Model\Model;
/**
* @property int $id
* @property int $order_id
* @property int $cycle_id
* @property int $kitchen_id
* @property int $sku_id
* @property int $spu_id
* @property int $user_id
* @property int $quantity
* @property string $unit_price
* @property int $is_comment
* @property int $copies
* @property int $status
* @property int $type
* @property string $create_time
* @property string $update_time
*/
class OrderGood extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'order_goods';
/**
* 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',
'order_id' => 'integer',
'cycle_id' => 'integer',
'kitchen_id' => 'integer',
'sku_id' => 'integer',
'spu_id' => 'integer',
'user_id' => 'integer',
'quantity' => 'integer',
'is_comment' => 'integer',
'copies' => 'integer',
'type' => 'integer'
];
const string CREATED_AT = 'create_time';
const string UPDATED_AT = 'update_time';
/**
* 根据订单获取商品id
* @param int $orderId
* @return array
*/
public function getGoodIdsByOrderId(int $orderId): array
{
return $this->where('order_id', $orderId)->select('sku_id')->selectRaw('SUM(`quantity`) as `quantity`')->groupBy('sku_id')->get()->toArray();
}
/**
* @param array $orderIds
* @return int
*/
public function isCateringByOrderIds(array $orderIds): int
{
return $this->whereIn('order_id', $orderIds)->update([
'status' => OrderCode::PLAN
]);
}
}