Rule.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/3/23
  6. * Time: 上午10:41
  7. */
  8. namespace app\common\models\frame;
  9. use Illuminate\Support\Facades\Schema;
  10. use app\common\models\BaseModel;
  11. class Rule extends BaseModel
  12. {
  13. public $table = 'rule';
  14. public $timestamps = false;
  15. public $attributes = [
  16. 'module' => 'yun_shop',
  17. 'displayorder' => 0,
  18. 'status' => 1,
  19. ];
  20. protected $guarded = [''];
  21. /**
  22. * Rule constructor.
  23. * @param array $param
  24. * @throws \Exception
  25. */
  26. public function __construct($param=[])
  27. {
  28. if($this->hasColumn('containtype')){ //用于兼容新版微擎新增的字段
  29. $param = $param ?: array('containtype'=> 'basic', 'reply_type'=> '1');
  30. $this->attributes = array_merge($this->attributes, $param);
  31. }
  32. // 新框架兼容微擎
  33. if (config('app.framework') == 'platform') {
  34. $this->table = 'yz_wechat_rule';
  35. } else {
  36. $this->table = 'rule';
  37. }
  38. parent::__construct();
  39. }
  40. /*
  41. * 通过rid 关键字主键id获取关键字规则详情
  42. *
  43. * @param varchar $name [ 模块标识:插件标识:主键ID 】如:sz_yi:designer:7
  44. *
  45. *
  46. * @return object */
  47. public static function getRuleByName($name)
  48. {
  49. return self::uniacid()->where('name', $name)->first();
  50. }
  51. /**
  52. * 定义字段名
  53. *
  54. * @return array */
  55. public function attributeNames() {
  56. return [
  57. 'module' => 'module字段不能为空\'',
  58. 'displayorder' => 'displayorder字段不能为空',
  59. 'status' => 'status字段不能为空',
  60. 'uniacid' => 'uniacid字段不能为空',
  61. 'name' => 'name字段不能为空'
  62. ];
  63. }
  64. /**
  65. * 字段规则
  66. *
  67. * @return array */
  68. public function rules()
  69. {
  70. return [
  71. 'module' => 'required',
  72. 'displayorder' => 'required',
  73. 'status' => 'required',
  74. 'uniacid' => 'required',
  75. 'name' => 'required'
  76. ];
  77. }
  78. }