Localchanceloption.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use yii\db\ActiveRecord;
  9. /**
  10. * Class Localchanceloption
  11. * @package app\models
  12. * @property integer $id
  13. * @property integer $channel_id
  14. * @property integer $type
  15. * @property integer $cat_id
  16. * @property string $group_name
  17. * @property string $name
  18. * @property string $values
  19. *
  20. *
  21. *
  22. **/
  23. class Localchanceloption extends \yii\db\ActiveRecord
  24. {
  25. /**
  26. * @inheritdoc
  27. */
  28. public static function tableName()
  29. {
  30. return '{{%localchanceloption}}';
  31. }
  32. public function rules()
  33. {
  34. return [
  35. [['id', 'channel_id','type','cat_id'], 'integer'],
  36. [["group_name", 'name', 'values'], 'string'],
  37. ];
  38. }
  39. /**
  40. * @inheritdoc
  41. */
  42. public function attributeLabels()
  43. {
  44. return [
  45. 'id' => "ID",
  46. 'channel_id' => "渠道ID",
  47. 'type' => "支付渠道类型",
  48. ];
  49. }
  50. /**
  51. * 获取配置数据
  52. * @param $name
  53. * @param int $channel_id
  54. * @param int $type
  55. * @param string $key
  56. * @param string $value
  57. * @return array
  58. */
  59. public static function get ($name, $channel_id = 0, $type = 0, $key = '', $value = '')
  60. {
  61. $query = self::find()->where([
  62. 'group_name' => $name,
  63. 'channel_id' => $channel_id,
  64. 'type' => $type,
  65. ])->select(['group_name','values','type']);
  66. if (is_array($name)) {
  67. $data = $query->asArray()->all();
  68. } else {
  69. $data = $query->asArray()->one();
  70. }
  71. if (empty($key) && empty($value) && !empty($data)){
  72. $data = array_column($data, $value,$key);
  73. }
  74. return $data;
  75. }
  76. }