| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- namespace addons\Store\common\models;
- use Exception;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_store_goods_reserve_time_spec".
- *
- * @property int $id
- * @property string|null $spec_time spec标题
- * @property string|null $start 开始时间点
- * @property string|null $end 结束时间点
- * @property int $reserve_time_id 商城id
- * @property int|null $reserve_sku_id 预约商品SKU
- * @property int $checked 是否选中
- * @property int $is_next 结束时间[0当日 1次日]
- * @property int $stock 库存
- * @property float $price 售价
- * @property float $original_price 原价(划线价仅展示)
- * @property float $cost_price 成本价
- * @property int $reserve_max_buy 每天最大预约数量
- * @property int $updated_at 修改时间
- * @property int $created_at 创建时间
- */
- class StoreGoodsReserveTimeSpec extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_addons_store_goods_reserve_time_spec';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['reserve_time_id', 'reserve_sku_id', 'checked', 'is_next', 'stock', 'reserve_max_buy', 'updated_at', 'created_at'], 'integer'],
- [['price', 'original_price', 'cost_price'], 'number'],
- [['spec_time'], 'string', 'max' => 16],
- [['start', 'end'], 'string', 'max' => 32],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'spec_time' => 'Spec Time',
- 'start' => 'Start',
- 'end' => 'End',
- 'reserve_time_id' => 'Reserve Time ID',
- 'reserve_sku_id' => 'Reserve Sku ID',
- 'checked' => 'Checked',
- 'is_next' => 'Is Next',
- 'stock' => 'Stock',
- 'price' => 'Price',
- 'original_price' => 'Original Price',
- 'cost_price' => 'Cost Price',
- 'reserve_max_buy' => 'Reserve Max Buy',
- 'updated_at' => 'Updated At',
- 'created_at' => 'Created At',
- ];
- }
- // 设置sku的可预约时间
- public static function setTimeSpec($reserveTime, $timeSpecs,&$totalStock)
- {
- try {
- array_map(function ($val) use (&$reserveTime,&$totalStock) {
- $model = new self();
- $model->loadDefaultValues();
- $attributes = [
- 'spec_time' => $val['spec_time'],
- 'start' => $val['start'],
- 'end' => $val['end'],
- 'reserve_time_id' => $reserveTime['id'],
- 'price' => $val['price'] ?? 0,
- 'original_price' => $val['original_price'] ?? 0,
- 'cost_price' => $val['cost_price'] ?? 0,
- 'reserve_max_buy' => $val['reserve_max_buy'] ?? 0,
- 'reserve_sku_id' => $reserveTime['reserve_sku_id'] ?? 0,
- 'stock' => $val['reserve_max_buy'] ?? 0,
- 'checked' => $val['checked'],
- 'is_next' => $val['is_next'],
- ];
- $totalStock += $val['reserve_max_buy'];
- if (!$model->load($attributes, '') || !$model->save()) {
- throw new Exception($model->getErrorMessage());
- }
- }, $timeSpecs);
- } catch (Exception $e) {
- if (isset($trans)) $trans->rollback();
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|