123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
- namespace app\models\system;
- use crmeb\traits\ModelTrait;
- use crmeb\basic\BaseModel;
- use app\models\system\SystemGroup as GroupModel;
- class SystemGroupDataMerchant extends BaseModel
- {
-
- protected $pk = 'id';
-
- protected $name = 'system_group_data_merchant';
- use ModelTrait;
- public static function merSet($mer_id)
- {
- return $mer_id ? self::where('mer_id', $mer_id) : new self;
- }
-
- public static function getList($params, $mer_id = '')
- {
- $model = self::merSet($mer_id);
- if ($params['gid'] !== '') $model = $model->where('gid', $params['gid']);
- if ($params['status'] !== '') $model = $model->where('status', $params['status']);
- $count = $model->count();
- $model = $model->order('sort desc,id ASC');
- $list = $model->page((int)$params['page'], (int)$params['limit'])
- ->select()
- ->each(function ($item) {
- $info = json_decode($item->value, true);
- foreach ($info as $index => $value) {
- if ($value["type"] == "checkbox") $info[$index]["value"] = implode(",", $value["value"]);
- }
- $item['value'] = $info;
- });
- foreach ($list as $key => $value) {
- foreach ($value['value'] as $k => $v) {
- $list[$key][$k] = $v['value'];
- }
- unset($list[$key]['value']);
- }
- $type = '';
- $Fields = GroupModel::getField($params['gid'])['fields'];
- foreach ($Fields as $item) {
- if ($item['type'] === 'upload') {
- $type = $item['title'];
- }
- }
- return compact('count', 'list', 'type');
- }
-
- public static function getGroupData($config_name, $limit = 0, $mer_id = '')
- {
- $group = SystemGroup::where('config_name', $config_name)->field('name,info,config_name')->find();
- if (!$group) return false;
- $group['data'] = self::getAllValue($config_name, $limit, $mer_id);
- return $group;
- }
-
- public static function getAllValue($config_name, $limit = 0, $mer_id = '')
- {
- $model = self::merSet($mer_id)->alias('a')->field('a.*,b.config_name')->join('system_group b', 'a.gid = b.id')
- ->where("b.config_name", $config_name)->where("a.status", 1)
- ->order('sort desc,id ASC');
- if ($limit > 0) $model->limit($limit);
- $data = [];
- $result = $model->select();
- if (!$result) return $data;
- foreach ($result as $key => $value) {
- $data[$key]["id"] = $value["id"];
- $fields = json_decode($value["value"], true);
- foreach ($fields as $index => $field) {
- $data[$key][$index] = $field["value"];
- }
- }
- return $data;
- }
-
- public static function getDateValue($id)
- {
- $value = self::alias('a')->where(array("id" => $id))->find();
- $data["id"] = $value["id"];
- $fields = json_decode($value["value"], true);
- foreach ($fields as $index => $field) {
- $data[$index] = $field["value"];
- }
- return $data;
- }
- }
|