StoreMiniCode.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace addons\Store\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use Yii;
  6. use yii\db\Exception;
  7. /**
  8. * This is the model class for table "qimall_addons_store_mini_code".
  9. *
  10. * @property int $id ID
  11. * @property int $mall_id 商城ID
  12. * @property int $store_id 门店id
  13. * @property int $type 1:推广码;2:收银台二维码
  14. * @property string $code 分享码
  15. * @property string $content 二维码参数
  16. * @property string|null $applet_code 小程序二维码图片地址
  17. * @property int $status 状态【1启用 0禁用 -1删除】
  18. * @property int $created_at 创建时间
  19. * @property int $updated_at 上次更新数据时间
  20. */
  21. class StoreMiniCode extends BaseActiveRecord
  22. {
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public static function tableName()
  27. {
  28. return '{{%addons_store_mini_code}}';
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function rules()
  34. {
  35. return [
  36. [['mall_id', 'store_id', 'type', 'status', 'created_at', 'updated_at'], 'integer'],
  37. [['content','code', 'applet_code'], 'string', 'max' => 255],
  38. ];
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function attributeLabels()
  44. {
  45. return [
  46. 'id' => 'ID',
  47. 'mall_id' => '商城ID',
  48. 'store_id' => '门店id',
  49. 'type' => '1:推广码;2:收银台二维码',
  50. 'code' => '分享码',
  51. 'content' => '二维码参数',
  52. 'applet_code' => '小程序二维码图片地址',
  53. 'status' => '状态【1启用 0禁用 -1删除】',
  54. 'created_at' => '创建时间',
  55. 'updated_at' => '上次更新数据时间',
  56. ];
  57. }
  58. public static function setData($params)
  59. {
  60. try {
  61. $model = new self();
  62. $model->loadDefaultValues();
  63. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  64. $res = $model->save();
  65. if ($res == false) throw new \Exception($model->getErrorMessage());
  66. return $model;
  67. } catch (\Exception $e) {
  68. self::$static_error = $e->getMessage();
  69. return false;
  70. }
  71. }
  72. /**
  73. * 清除小程序二维码
  74. *
  75. * @param integer $mall_id
  76. * @return boolean
  77. */
  78. public static function cleanMiniCodeByMallId(int $mall_id)
  79. {
  80. return self::updateAll(
  81. ['applet_code' => ''],
  82. ['mall_id' => $mall_id]
  83. );
  84. }
  85. }