RuleKeyword.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/3/23
  6. * Time: 上午10:32
  7. */
  8. namespace app\common\models\frame;
  9. use app\common\models\BaseModel;
  10. class RuleKeyword extends BaseModel
  11. {
  12. public $table = 'rule_keyword';
  13. public $timestamps = false;
  14. protected $guarded = [''];
  15. public $attributes = array(
  16. 'module' => 'yun_shop',
  17. 'type' => 1,
  18. 'displayorder' => 0,
  19. 'status' => 1
  20. );
  21. protected static $module = 'yun_shop';
  22. public function __construct()
  23. {
  24. // 新框架兼容微擎
  25. if (config('app.framework') == 'platform') {
  26. $this->table = 'yz_wechat_rule_keyword';
  27. } else {
  28. $this->table = 'rule_keyword';
  29. }
  30. parent::__construct();
  31. }
  32. /*
  33. * 关键字是否存在,存在返回id,不存在返回false;
  34. *
  35. * @param string $keyword
  36. *
  37. * @return mixed $id or false*/
  38. public static function hasKeyword($keyword)
  39. {
  40. $id = self::uniacid()->where('module', static::$module)->where('content', $keyword)->value('id');
  41. return empty($id) ? false : $id;
  42. }
  43. public static function delKeyword($keyword)
  44. {
  45. return self::uniacid()
  46. ->where('module', static::$module)
  47. ->where('content', $keyword)
  48. ->delete();
  49. }
  50. /*
  51. * 通过 roleId 修改关键字
  52. *
  53. * @param int $roleId
  54. * @param string $keyrord
  55. *
  56. * @return mixed $id or false*/
  57. public static function updateKeywordByRoleId($roleId, $keyword)
  58. {
  59. return static::uniacid()
  60. ->where('rid', $roleId)
  61. ->where('module', static::$module)
  62. ->update(['content' => trim($keyword)]);
  63. }
  64. public static function destroyKeywordByRuleId($roleId)
  65. {
  66. return static::uniacid()
  67. ->where('rid', $roleId)
  68. ->where('module', static::$module)
  69. ->delete();
  70. }
  71. /**
  72. * 定义字段名
  73. *
  74. * @return array */
  75. public function attributeNames() {
  76. return [
  77. 'uniacid' => 'uniacid字段不能为空',
  78. 'module' => 'module字段不能为空',
  79. 'displayorder' => 'displayorder字段不能为空',
  80. 'status' => 'status字段不能为空',
  81. 'rid' => 'rid字段不能为空',
  82. 'content' => 'content字段不能为空',
  83. 'type' => 'type字段不能为空'
  84. ];
  85. }
  86. /**
  87. * 字段规则
  88. *
  89. * @return array */
  90. public function rules()
  91. {
  92. return [
  93. 'uniacid' => 'required',
  94. 'module' => 'required',
  95. 'displayorder' => 'required',
  96. 'status' => 'required',
  97. 'rid' => 'required',
  98. 'content' => 'required',
  99. 'type' => 'required'
  100. ];
  101. }
  102. }