| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?php
- namespace addons\CloudStockTwo\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use common\models\goods\Goods;
- use common\models\order\Order;
- use common\models\order\OrderDetail;
- use common\models\user\User;
- use Yii;
- /**
- * This is the model class for table "{{%addons_cloud_stock_fill_order".
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property int $user_id 补货代理商用户id
- * @property int $trade_id 支付流水记录 id
- * @property float $pay_money 支付金额
- * @property string $order_no 补货订单编号
- * @property string $trade_no 支付流水号
- * @property int $is_pay 是否支付
- * @property int $goods_id 商品id
- * @property int $num 补货商品数量
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class CloudStockTwoFillOrder extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_cloud_stock_two_fill_order}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'order_no', 'goods_id'], 'required'],
- [['mall_id', 'user_id', 'trade_id', 'is_pay', 'goods_id', 'num', 'status', 'created_at', 'updated_at'], 'integer'],
- [['pay_money','reward_unit_price'], 'number'],
- [['order_no', 'trade_no'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城id',
- 'user_id' => '补货代理商用户id',
- 'trade_id' => '支付流水记录 id',
- 'pay_money' => '支付金额',
- 'order_no' => '补货订单编号',
- 'trade_no' => '支付流水号',
- 'is_pay' => '是否支付',
- 'goods_id' => '商品id',
- 'num' => '补货商品数量',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'reward_unit_price' => 'Reward Unit Price',
- ];
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select(['id', 'nickname', 'avatar_url', 'mobile']);
- }
- public function getGoods()
- {
- return $this->hasOne(Goods::class, ['id' => 'goods_id'])->select(['id', 'goods_name', 'cover_pic']);
- }
- public static function setData(int $mall_id, array $data)
- {
- if (!empty($data['id'])) {
- $model = self::findOne(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'id' => $data['id']]);
- if (empty($model)) {
- self::$static_error = '数据异常';
- return false;
- }
- } else {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $mall_id;
- }
- foreach ($data as $key => $val) {
- $model->$key = $val;
- }
- // dd($model);
- if (!$model->save()) {
- self::$static_error = '保存数据失败:' . $model->getErrorMessage();
- return false;
- }
- return $model;
- }
- public static function check($params): bool
- {
- $order_no_arr = $params['order_no_arr'];
- $payment_order_list = $params['payment_order_list'];
- $counts = self::find()->where(['order_no'=>$order_no_arr,'is_pay'=>0])->count();
- if ($counts != count($payment_order_list)) {
- self::$static_error = '补货订单不一致';
- return false;
- }
- return true;
- }
- }
|