ScratchOrderModel.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace addons\Scratch\common\models;
  3. use addons\Coupon\common\models\AddonsCoupon;
  4. use addons\Scratch\common\enums\ScratchEnum;
  5. use common\models\base\BaseActiveRecord;
  6. use common\models\goods\Goods;
  7. use common\models\mall\MallAddons;
  8. use common\models\order\Order;
  9. /**
  10. * Class ScratchOrderModel
  11. * @package addons\Scratch\common\models
  12. */
  13. class ScratchOrderModel extends BaseActiveRecord
  14. {
  15. /**
  16. * {@inheritdoc}
  17. */
  18. public static function tableName()
  19. {
  20. return '{{%addons_scratch_order}}';
  21. }
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public function rules()
  26. {
  27. return [
  28. [['mall_id', 'scratch_log_id', 'order_id'], 'required'],
  29. [['mall_id', 'scratch_log_id', 'order_id', 'order_id', 'order_id', 'status'], 'integer'],
  30. ];
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function attributeLabels()
  36. {
  37. return [
  38. 'id' => 'ID',
  39. 'mall_id' => 'Mall ID',
  40. 'status' => '状态-1 删除 0 关闭 1开启',
  41. ];
  42. }
  43. /**
  44. * @return \yii\db\ActiveQuery
  45. */
  46. public function getOrder()
  47. {
  48. return $this->hasOne(Order::className(), ['id' => 'order_id']);
  49. }
  50. /**
  51. * @param $mallId
  52. * @param $params
  53. * @return ScratchOrderModel
  54. * @throws \Exception
  55. */
  56. public static function setData($params)
  57. {
  58. try {
  59. $model = new self();
  60. $model->mall_id = $params['mall_id'] ?? '';
  61. $model->scratch_log_id = $params['scratch_log_id'] ?? 0;
  62. $model->order_id = $params['order_id'] ?? 0;
  63. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  64. return $model;
  65. } catch (\Exception $exception) {
  66. throw new \Exception($exception->getMessage());
  67. }
  68. }
  69. }