123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace app\admin\model;
- use think\model;
- use think\facade\Db;
- class Contact extends Model
- {
- protected $table = 'cp_contact';
- // protected $autoWriteTimestamp = true;
- // public function getAuditStatusAttr($value){
- // $status = [
- // 0 => '未审核',
- // 1 => '未通过',
- // 2 => '已通过',
- // ];
- // return $status[$value];
- // }
- /**
- * 添加数据
- * @param $param
- */
- public function addContact($param)
- {
- $insertId = 0;
- try {
- $param['create_time'] = time();
- $insertId = $this->strict(false)->field(true)->insertGetId($param);
- add_log('add', $insertId, $param);
- } catch (\Exception $e) {
- return to_assign(1, '操作失败,原因:' . $e->getMessage());
- }
- return to_assign(0, '操作成功', ['aid' => $insertId]);
- }
- /**
- * 编辑信息
- * @param $param
- */
- public function editReport($param)
- {
- try {
- $param['update_time'] = time();
- $this->where('id', $param['id'])->strict(false)->field(true)->update($param);
- add_log('edit', $param['id'], $param);
- } catch (\Exception $e) {
- return to_assign(1, '操作失败,原因:' . $e->getMessage());
- }
- return to_assign();
- }
- /**
- * 根据id获取信息
- * @param $id
- */
- public function getContactById($id)
- {
- $info = $this->where('id', $id)->find();
- return $info;
- }
- /**
- * 删除信息
- * @param $id
- * @return array
- */
- public function delContactById($id, $type = 0)
- {
- if ($type == 0) {
- //逻辑删除
- try {
- $param['delete_time'] = time();
- $this->where('id', $id)->update(['delete_time' => time()]);
- add_log('delete', $id);
- } catch (\Exception $e) {
- return to_assign(1, '操作失败,原因:' . $e->getMessage());
- }
- } else {
- //物理删除
- try {
- $this->where('id', $id)->delete();
- add_log('delete', $id);
- } catch (\Exception $e) {
- return to_assign(1, '操作失败,原因:' . $e->getMessage());
- }
- }
- return to_assign();
- }
- public function detail($id)
- {
- $detail = Db::name('Contact')->where(['id' => $id])->find();
- $detail["maker_name"] = get_admin($detail["maker_id"])["nickname"];
- return $detail;
- }
- }
|