StoreRefundAddress.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace addons\Store\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use Yii;
  6. /**
  7. * This is the model class for table "qimall_addons_store_refund_address".
  8. *
  9. * @property int $id
  10. * @property int $mall_id
  11. * @property int $store_id 门店id
  12. * @property string $refund_name 退货名称
  13. * @property string $name 联系人
  14. * @property string $mobile 退换货手机号
  15. * @property string $address 退换货地址
  16. * @property int $status 状态[0禁用 1启用 -1删除]
  17. * @property int $created_at 创建时间
  18. * @property int $updated_at 修改时间
  19. */
  20. class StoreRefundAddress extends BaseActiveRecord
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public static function tableName()
  26. {
  27. return '{{%addons_store_refund_address}}';
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['mall_id', 'store_id', 'status', 'created_at', 'updated_at'], 'integer'],
  36. [['refund_name', 'name', 'address'], 'string', 'max' => 255],
  37. [['mobile'], 'string', 'max' => 11],
  38. ];
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function attributeLabels()
  44. {
  45. return [
  46. 'id' => 'ID',
  47. 'mall_id' => 'Mall ID',
  48. 'store_id' => '门店id',
  49. 'refund_name' => '退货名称',
  50. 'name' => '联系人',
  51. 'mobile' => '退换货手机号',
  52. 'address' => '退换货地址',
  53. 'status' => '状态[0禁用 1启用 -1删除]',
  54. 'created_at' => '创建时间',
  55. 'updated_at' => '修改时间',
  56. ];
  57. }
  58. public static function setData(array $params)
  59. {
  60. try {
  61. if (!empty($params['id'])) {
  62. $where = ['id' => $params['id'], ['status' => StatusEnum::ENABLED]];
  63. if (isset($params['mall_id'])) $where[] = ['mall_id' => $params['mall_id']];
  64. if (isset($params['store_id'])) $where[] = ['store_id' => $params['store_id']];
  65. $model = self::findOne($where);
  66. if (empty($model)) throw new \Exception('服务不存在或已删除');
  67. } else {
  68. $model = new self();
  69. $model->loadDefaultValues();
  70. }
  71. if (!$model->load($params, '') || !$model->save()) throw new \PHPUnit\Util\Exception($model->getErrorMessage());
  72. return $model;
  73. } catch (\Exception $e) {
  74. self::$static_error = $e->getMessage();
  75. return false;
  76. }
  77. }
  78. }