123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace addons\qingdongams\model;
- use think\Exception;
- use think\Model;
- use traits\model\SoftDelete;
- use addons\qingdongams\model\DailyDraft;
- /**
- *工作报告
- */
- class Daily Extends Model {
- use SoftDelete;
- // 表名,不含前缀
- protected $name = 'qingdongams_daily';
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = 'deletetime';
- //获取创建时间
- public function getCreatetimeAttr($value){
- return date('Y-m-d H:i',$value);
- }
- public function getOtherAttr($value){
- return json_decode($value,true);
- }
- //销售
- public function staff() {
- return $this->hasOne(Staff::class, 'id', 'create_staff_id')->field('id,img,name,post');
- }
- //已读
- public function read(){
- return $this->hasMany(DailyRead::class, 'daily_id', 'id')->field('daily_id,createtime');
- }
- /**
- * @desc 备注
- * @update_date 2021/6/9 更新时间
- * @author zhangwei
- */
- public static function createDaily($params) {
- //自定义字段
- $other = [];
- foreach ($params as $name => $val) {
- if (strstr( $name,'other_') !== false) {
- if(is_array($val)){
- $other[$name] = implode(',',$val);
- }else{
- $other[$name] = $val;
- }
- unset($params[$name]);
- }
- }
- $params['other']=json_encode($other);
- $model = new self;
- // 调用当前模型对应的User验证器类进行数据验证
- $result = $model->allowField(true)->save($params);
- if (false === $result) {
- // 验证失败 输出错误信息
- throw new Exception($model->getError());
- }
- $lastId=$model->getLastInsID();
- if (isset($params['reminds_id'])) {//发送通知
- $staff_ids = explode(',', $params['reminds_id']);
- foreach ($staff_ids as $staff_id) {
- //发送通知
- Message::addMessage(Message::DAILY_TYPE, $lastId, $staff_id, $params['create_staff_id']);
- }
- }
- return $lastId;
- }
- /**
- * 修改
- * @param $params
- * @return string
- * @throws Exception
- */
- public static function updateDaily($params) {
- //自定义字段
- $other = [];
- foreach ($params as $name => $val) {
- if (strstr( $name,'other_') !== false) {
- if(is_array($val)){
- $other[$name] = implode(',',$val);
- }else{
- $other[$name] = $val;
- }
- unset($params[$name]);
- }
- }
- $params['other']=json_encode($other);
- if(isset($params['reminds_id'])){
- unset($params['reminds_id']);
- }
- $model = new self;
- // 调用当前模型对应的User验证器类进行数据验证
- $result = $model->allowField(true)->save($params,['id'=>$params['id']]);
- if (false === $result) {
- // 验证失败 输出错误信息
- throw new Exception($model->getError());
- }
- $lastId=$model->getLastInsID();
- $where['create_staff_id'] = $params['create_staff_id'];
- $where['type'] = $params['type'];
- DailyDraft::where($where)->update(array('deletetime'=>time()));
- return $lastId;
- }
- public static function getTypeName($types)
- {
- switch($types){
- case '日报':
- $typeinfo ='daily';
- break;
- case '周报':
- $typeinfo ='weekly';
- break;
- case '月报':
- $typeinfo ='monthly';
- break;
- case '季报':
- $typeinfo ='quarterly';
- break;
- case '年报':
- $typeinfo ='yearly';
- break;
- default:
- $typeinfo ='daily';
- break;
- }
- return $typeinfo;
- }
- }
|