123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- namespace app\common\dao\system\groupData;
- use app\common\dao\BaseDao;
- use app\common\model\BaseModel;
- use app\common\model\system\groupData\SystemGroupData;
- use think\db\BaseQuery;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\DbException;
- use think\db\exception\ModelNotFoundException;
- use think\Model;
- /**
- * Class GroupDataDao
- * @package app\common\dao\system\groupData
- * @author zfy
- * @day 2020-03-27
- */
- class GroupDataDao extends BaseDao
- {
- /**
- * @return BaseModel
- * @author zfy
- * @day 2020-03-30
- */
- protected function getModel(): string
- {
- return SystemGroupData::class;
- }
- /**
- * @param $merId
- * @param $groupId
- * @return BaseQuery
- * @author zfy
- * @day 2020-03-30
- */
- public function getGroupDataWhere($merId, $groupId): BaseQuery
- {
- return SystemGroupData::getDB()->withAttr('value', function ($val) {
- return json_decode($val, true);
- })->where('mer_id', $merId)->where('group_id', $groupId)->order('sort DESC');
- }
- /**
- * @param $merId
- * @param $groupId
- * @param int|null $page
- * @param int|null $limit
- * @return array
- * @author zfy
- * @day 2020/5/27
- */
- public function getGroupData($merId, $groupId, ?int $page = null, ?int $limit = 10)
- {
- $query = SystemGroupData::getDB()
- ->where('mer_id', $merId)->where('group_id', $groupId)
- ->where('status', 1)
- ->where('')
- ->order('sort DESC');
- if (!is_null($page)) $query->page($page, $limit);
- $groupData = [];
- foreach ($query->column('value') as $k => $v) {
- $groupData[] = json_decode($v, true);
- }
- return $groupData;
- }
- public function groupDataCount($merId, $groupId)
- {
- return SystemGroupData::getDB()->where('mer_id', $merId)->where('group_id', $groupId)->where('status', 1)->count();
- }
- /**
- * @param $merId
- * @param $groupId
- * @param int|null $page
- * @param int|null $limit
- * @return array
- * @author zfy
- * @day 2020/6/3
- */
- public function getGroupDataId($merId, $groupId, ?int $page = null, ?int $limit = 10)
- {
- $query = SystemGroupData::getDB()->where('mer_id', $merId)->where('group_id', $groupId)->where('status', 1)->order('sort DESC');
- if (!is_null($page)) $query->page($page, $limit);
- $groupData = [];
- foreach ($query->column('value', 'group_data_id') as $k => $v) {
- $groupData[] = ['id' => $k, 'data' => json_decode($v, true)];
- }
- return $groupData;
- }
- /**
- * @param $merId
- * @param $id
- * @param $data
- * @return int
- * @throws DbException
- * @author zfy
- * @day 2020-03-30
- */
- public function merUpdate($merId, $id, $data)
- {
- $data['value'] = json_encode($data['value']);
- return SystemGroupData::getDB()->where('group_data_id', $id)->where('mer_id', $merId)->update($data);
- }
- /**
- * @param $merId
- * @param $id
- * @return int
- * @throws DbException
- * @author zfy
- * @day 2020-03-30
- */
- public function merDelete($merId, $id)
- {
- return SystemGroupData::getDB()->where('mer_id', $merId)->where('group_data_id', $id)->delete();
- }
- /**
- * @param int $merId
- * @param int $id
- * @return bool
- * @author zfy
- * @day 2020-04-02
- */
- public function merExists(int $merId, int $id)
- {
- return ($this->getModel())::getDB()->where('mer_id', $merId)->where($this->getPk(), $id)->count() > 0;
- }
- /**
- * @param int $groupId
- * @return int
- * @throws DbException
- * @author zfy
- * @day 2020-05-16
- */
- public function clearGroup(int $groupId)
- {
- return SystemGroupData::getDB()->where('group_id', $groupId)->delete();
- }
- /**
- * @param $id
- * @param $merId
- * @return array|Model|null
- * @throws DbException
- * @throws DataNotFoundException
- * @throws ModelNotFoundException
- * @author zfy
- * @day 2020/6/2
- */
- public function merGet($id, $merId)
- {
- $data = SystemGroupData::getDB()->where('group_data_id', $id)->where('mer_id', $merId)->find();
- return $data ? $data['value'] : null;
- }
- }
|