123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- /*
- * @Author: wang jun
- * @Date: 2022-01-18 09:43:33
- * @Last Modified by: wang jun
- * @Last Modified time: 2022-01-19 16:39:15
- */
- namespace app\index\model;
- use think\Model;
- class partymodel extends Model
- {
- protected $table = 't_party';
- public function insertData($data)
- {
- if (!isset($data['crate_time']) || empty($data['crate_time']) || !is_string($data['crate_time'])) {
- $data['crate_time'] = date("Y-m-d H:i:s");
- }
- $data = $this->formatData($data);
- if (empty($data)) {
- return false;
- }
- $id = $this->insertGetId($data);
- return empty($id) ? false : $id;
- }
- /**
- * 校验入库数据
- * 20220119
- */
- private function formatData($data)
- {
- $useData = [];
- $fields = $this->getTableFields();
- foreach ($data as $key => $value) {
- if (in_array($key, $fields)) {
- $useData[$key] = $value;
- }
- }
- return $useData;
- }
- public function getInfo($where, $field = "*", $row = true)
- {
- $info = $this->field($field)->where($where);
- if ($row) {
- $info = $info->find();
- } else {
- $info = $info->select();
- }
- return empty($info) ? false : $info;
- }
- public function updateinfo($where, $updateData)
- {
- $row = $this->where($where)->update($updateData);
- return empty($row) ? false : $row;
- }
- public function deleteinfo($where)
- {
- $row = $this->where($where)->delete();
- return empty($row) ? false : $row;
- }
- public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
- {
- $sqlObj = $this->where($where);
- if ("count" != $field) {
- $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
- if ($row) {
- $data = $sqlObj->find();
- } else {
- $data = $sqlObj->select();
- }
- } else {
- $data = $sqlObj = $sqlObj->count();
- }
- return $data;
- }
- /**
- * 根据时间获取活动
- * 20220119
- * wj
- */
- public function getinfobytime($time)
- {
- $where = [
- ['isactive' ,'=', 1],
- ['start_time' ,'<=', $time],
- ['end_time' ,'>=', $time],
- ];
- $order = "id asc";
- $info = $this->where($where)->order($order)->find();
- return empty($info) ? false : $info;
- }
- /**
- * 根据时间获取活动
- * 20220119
- * wj
- */
- public function getinfobyid($id)
- {
- $where = [
- 'id' => $id,
- 'isactive' => 1,
- ];
- $order = "id asc";
- $info = $this->where($where)->order($order)->find();
- return empty($info) ? false : $info;
- }
- }
|