FCleanForm.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. class FCleanForm extends Base
  6. {
  7. protected $createTime = 'create_time';
  8. protected $updateTime = 'update_time';
  9. public $table = 'f_clean_form';
  10. protected $validateName = 'FCleanForm';
  11. public function updates(){
  12. $data = request()->post();
  13. $data['org_id'] = cur_org_id();
  14. $result = validate($this->validateName)->check($data,[],'');
  15. if(true !== $result){
  16. $this->error = validate($this->validateName)->getError();
  17. return false;
  18. }
  19. $id = $data['id'];
  20. unset($data['id']);
  21. if($id > 0){
  22. $data['update_time'] = date('Y-m-d H:i:s');
  23. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  24. }else{
  25. $data['create_time'] = date('Y-m-d H:i:s');
  26. $ret = $this->allowField(true)->save($data);
  27. }
  28. if(!$ret){
  29. $this->error = '操作失败';
  30. return false;
  31. }
  32. return true;
  33. }
  34. // 检查几个任务内容是否在同一分类下,在同一分类下返回分类ID
  35. public function check_form_type($ids)
  36. {
  37. $ret = Db::name('f_clean_form')
  38. ->alias('clean_form')
  39. ->join('f_clean_type clean_type','clean_type.id = clean_form.type_id')
  40. ->field('clean_form.id,clean_form.title,clean_type.parent_id')
  41. ->whereIn('clean_form.ID',$ids)
  42. ->select();
  43. $types = array();
  44. foreach ($ret as $k=>$v){
  45. if(empty($types)){
  46. $types[] = $v['parent_id'];
  47. } else if(!in_array($v['parent_id'],$types)){
  48. $types[] = $v['parent_id'];
  49. }
  50. }
  51. return count($types) == 1 ? $types[0] : 0;
  52. }
  53. public function queryAddByForm($recordId,$formId){ // $recordId 任务id $formId 表单id
  54. $record = Db::name('f_clean_record')->where('task_id',$recordId)
  55. ->where('form_id',$formId)
  56. ->find();
  57. $items = [];
  58. if($record){
  59. $addrlist = json_decode($record['check_json'],true);
  60. foreach ($addrlist as $k=>$v){
  61. $address = Db::name('address')->where('id',$v['id'])
  62. ->value('title');
  63. $addrlist[$k]['address_name'] = $address;
  64. }
  65. $items = Db::name('f_clean_record_items')
  66. ->alias('cr')
  67. ->join('mate_goods mm','cr.items_id=mm.id','left')
  68. ->where('cr.record_id',$record['id'])
  69. ->field('cr.items_id as itemsId,mm.title,cr.total,cr.money')
  70. ->select();
  71. }else{
  72. $address = Db::name('f_clean_form')
  73. ->where('id',$formId)->find();
  74. $addrs = explode(',',$address['address_ids']);
  75. $alist = Db::name('address')
  76. ->where('id','in',$addrs)->select();
  77. $addrlist = [];
  78. foreach ($alist as $k=>$v){
  79. $d = [
  80. 'address_id' => $v['id'],
  81. 'status' => 0,
  82. 'address_name' => $v['title']
  83. ];
  84. $addrlist[] = $d;
  85. }
  86. }
  87. $data = [
  88. 'address' => $addrlist,
  89. 'remark' => $record?$record['content']:'',
  90. 'items' => $items?$items:[]
  91. ];
  92. return $data;
  93. }
  94. }