123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- class CleanForm extends Base
- {
- protected $createTime = 'create_time';
- protected $updateTime = 'update_time';
- public $table = 'clean_form';
- protected $validateName = 'CleanForm';
- public function updates(){
- $data = request()->post();
- $data['org_id'] = cur_org_id();
- $result = validate($this->validateName)->check($data,[],'');
- if(true !== $result){
- $this->error = validate($this->validateName)->getError();
- return false;
- }
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $data['update_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $data['create_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- $this->error = '操作失败';
- return false;
- }
- return true;
- }
- // 检查几个任务内容是否在同一分类下,在同一分类下返回分类ID
- public function check_form_type($ids)
- {
- $ret = Db::name('clean_form')
- ->alias('clean_form')
- ->join('clean_type clean_type','clean_type.id = clean_form.type_id')
- ->field('clean_form.id,clean_form.title,clean_type.parent_id')
- ->whereIn('clean_form.ID',$ids)
- ->select();
- $types = array();
- foreach ($ret as $k=>$v){
- if(empty($types)){
- $types[] = $v['parent_id'];
- } else if(!in_array($v['parent_id'],$types)){
- $types[] = $v['parent_id'];
- }
- }
- return count($types) == 1 ? $types[0] : 0;
- }
- public function queryAddByForm($recordId,$formId){ // $recordId 任务id $formId 表单id
- $record = Db::name('clean_record')->where('task_id',$recordId)
- ->where('form_id',$formId)
- ->find();
- $items = [];
- if($record){
- $addrlist = json_decode($record['check_json'],true);
- foreach ($addrlist as $k=>$v){
- $address = Db::name('address')->where('id',$v['id'])
- ->value('title');
- $addrlist[$k]['address_name'] = $address;
- }
- $items = Db::name('clean_record_items')
- ->alias('cr')
- ->join('mate_goods mm','cr.items_id=mm.id','left')
- ->where('cr.record_id',$record['id'])
- ->field('cr.items_id as itemsId,mm.title,cr.total,cr.money')
- ->select();
- }else{
- $address = Db::name('clean_form')
- ->where('id',$formId)->find();
- $addrs = explode(',',$address['address_ids']);
- $alist = Db::name('address')
- ->where('id','in',$addrs)->select();
- $addrlist = [];
- foreach ($alist as $k=>$v){
- $d = [
- 'address_id' => $v['id'],
- 'status' => 0,
- 'address_name' => $v['title']
- ];
- $addrlist[] = $d;
- }
- }
- $data = [
- 'address' => $addrlist,
- 'remark' => $record?$record['content']:'',
- 'items' => $items?$items:[]
- ];
- return $data;
- }
- }
|