123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace app\common\model;
- use think\Db;
- class OrderType extends Base
- {
- protected $createTime = 'create_time';
- protected $updateTime = 'update_time';
- protected $table = 'order_type';
- protected $validateName = 'OrderType';
- 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;
- }
- if($data['type']==1){
- if(empty($data['parent_id'])){
- $this->error = '请选择报修类型';
- return false;
- }
- }
- $id = $data['id'];
- unset($data['id']);
- unset($data['type']);
- 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;
- }
- //获取报修类型
- public function list($orgId=0){
- if($orgId==0){
- $orgId = cur_org_id();
- }
- $list =$this
- ->where('parent_id',0)
- ->where('enable',1)
- ->where('del',0)
- ->where('org_id',$orgId)
- ->select()
- ->toArray();
- return $list;
- }
- //获取报修事项
- public function getList($orgId=0){
- if($orgId==0){
- $orgId = cur_org_id();
- }
- $list =$this
- ->where('parent_id','>',0)
- ->where('enable',1)
- ->where('del',0)
- ->where('org_id',$orgId)
- ->select()
- ->toArray();
- foreach ($list as $k=>$v){
- $parent_title = $this->getTableField('order_type',['id'=>$v['parent_id']],'title');
- $list[$k]['title'] ='['.$parent_title.']'.$v['title'];
- $list[$k]['count'] = Db::name('order_repair')->where('type_id',$v['id'])->count();
- }
- $list = list_sort_by($list,'count','desc');
- return $list;
- }
- //根据订单id获报修类型和地点
- public function getTypeByOrderId($orderId){
- $order_repair = Db::name('order_repair')
- ->where('order_id',$orderId)
- ->find();
- if($order_repair){
- $info = $this->where('id',$order_repair['type_id'])->find();
- $pInfo = $this->where('id',$info['parent_id'])->find();
- $addressTitle = Db::name('address')
- ->where('id',$order_repair['address_id'])
- ->find();
- $pInfo['address_title'] = $addressTitle['title'];
- $pInfo['child_title'] = $info['title'];
- $pInfo['type_id'] = $order_repair['type_id'];
- $pInfo['address_id'] = $order_repair['address_id'];
- $pInfo['repair_priority_index'] = $order_repair['repair_priority'];
- $pInfo['repair_priority'] = $order_repair['repair_priority']==1?'可延缓':($order_repair['repair_priority']==2?"普通":"紧急");
- return $pInfo;
- }
- return false;
- }
- }
|