123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- <?php
- namespace app\admin\controller\qingdongams\customer;
- use addons\qingdongams\model\ConsumeDetail;
- use addons\qingdongams\model\ExamineRecord;
- use addons\qingdongams\model\File;
- use addons\qingdongams\model\Flow;
- use addons\qingdongams\model\Message;
- use addons\qingdongams\model\Staff;
- use app\admin\controller\qingdongams\Base;
- use addons\qingdongams\model\ContractOther;
- use addons\qingdongams\model\Form;
- use addons\qingdongams\model\Contacts;
- use addons\qingdongams\model\Customer;
- use addons\qingdongams\model\OperationLog;
- use addons\qingdongams\model\Record;
- use addons\qingdongams\model\ContractFile;
- use think\Db;
- use think\Exception;
- /**
- * 费用管理
- * @desc 操作文档:https://doc.fastadmin.net/qingdongams
- * @desc 软件介绍:https://www.fastadmin.net/store/qingdongams.html
- * @desc 售后微信:qingdong_crm
- */
- class Consume extends Base
- {
- protected $relationSearch = true;
- /**
- * @var \addons\qingdongams\model\Consume
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \addons\qingdongams\model\Consume;
- }
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- if ($this->request->isAjax()) {
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- //0:全部 1:我负责的 2:下属负责的
- $type = input('type', 0);
- switch ($type) {
- case 1:
- $staff = Staff::info();
- $wheres['staff_id'] = $staff->id;
- break;
- case 2:
- $wheres['staff_id'] = array('in', Staff::getLowerStaffId());
- break;
- default:
- $wheres['staff_id'] = array('in', Staff::getMyStaffIds());
- break;
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $list = $this->model->where($where)->where($wheres)->with(['customer', 'staff'])->order($sort, $order)->paginate($limit);
- $result = array("total" => $list->total(), "rows" => $list->items());
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 添加
- */
- public function add()
- {
- if ($this->request->isPost()) {
- $params = $this->request->post("row/a");
- if ($params) {
- $params = $this->preExcludeFields($params);
- // 表单验证
- if (($result = $this->qingdongamsValidate($params, 'Consume', 'create')) !== true) {
- $this->error($result);
- }
- $result = false;
- $data = $this->request->post('row/a');
- // if(isset($data['flow_staff_ids'])){
- // if(!$data['flow_staff_ids']){
- // $this->error('请选择审批人');
- // }
- // }
- $params['staff_id'] = $this->_staff->id;
- $params['customer_id'] = $data['customer_id'];
- $params['money'] = $data['money'];
- $params['number'] = $data['number'];
- $params['submit_date'] = $data['submit_date'];
- $params['detail'] = $data['detail']??[];
- Db::startTrans();
- try {
- $result = $this->model::createConsume($params);
- Db::commit();
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if ($result !== false) {
- $this->success('添加成功');
- } else {
- $this->error(__('No rows were inserted'));
- }
- }
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $flow = Flow::getsteplist(Flow::CONSUME_STATUS);
- if (empty($flow)) {
- $this->error('无可用审批流,请联系管理员');
- }
- $customer_id = input('customer_id', null);
- $this->assign('customer_id', $customer_id);
- $this->assign('relation_type', input('relation_type'));
- $this->assign('relation_id', input('relation_id'));
- $this->assign('customer', Customer::get($customer_id));
- $this->assign('flow', $flow);
- $this->assign('staff', Staff::getStaff());
- $this->assign('number',$this->model::getNumber());
- $this->assign('consumetype',$this->model::getconsumetype());
- return $this->view->fetch();
- }
- private function operateParasm($datas)
- {
- $detail_field = ['consume_type', 'consume_date', 'car_number', 'consume_money', 'start_mileage', 'end_mileage', 'mileage', 'file_ids', 'remark', 'detail_id'];
- $list = [];
- foreach ($datas as $k => $v) {
- if (in_array($k, $detail_field) && is_array($v)) {
- foreach ($v as $key => $val) {
- if ($k == 'detail_id') {
- $k = 'id';
- }
- $list[$key][$k] = $val;
- }
- }
- }
- return array_values($list);
- }
- /**
- * 修改费用
- */
- public function edit($ids = null)
- {
- $map['id'] = $ids;
- if ($this->request->isAjax()) {
- $params = $this->request->post('row/a');
- $params = $this->preExcludeFields($params);
- $row = $this->model::where(['id' => $ids, 'check_status' => ['in', [0, 1, 3, 4, 5]]])->find();
- if (empty($row)) {
- $this->error('审核通过的费用不可编辑');
- }
- $data = $this->request->post('row/a');
- $params['staff_id'] = $this->_staff->id;
- $params['customer_id'] = $data['customer_id'];
- $params['money'] = $data['money'];
- $params['number'] = $data['number'];
- $params['submit_date'] = $data['submit_date'];
- $params['detail'] = $data['detail']??[];
- Db::startTrans();
- try {
- $params['id'] = $ids;
- $result = $this->model::updateConsume($params);
- Db::commit();
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if ($result !== false) {
- $this->success('修改成功');
- } else {
- $this->error('修改失败');
- }
- }
- $row = $this->model->where($map)->with(['customer'])->find();
- if ($row['file_ids']) {
- $wheres['id'] = array('in', $row['file_ids']);
- $file = File::where($wheres)->column('file_path');
- $row['file_ids'] = implode(',', $file);
- }
- $flow = Flow::getsteplist(Flow::CONSUME_STATUS);
- if (empty($flow)) {
- $this->error('无可用审批流,请联系管理员');
- }
- $this->assign('flow', $flow);
- $row=$row->toArray();
- $detail=ConsumeDetail::where(['consume_id'=>$ids])->select();
- if($detail){
- $detail=collection($detail)->toArray();
- }
- $row['detail']= $detail;
- foreach ($row['detail'] as &$d){
- $file_path=File::where(['id'=>['in',explode(',',$d['file_ids'])]])->column('file_path');
- $d['file_ids']=implode(',',$file_path);
- }
- $this->view->assign("row", $row);
- $this->assign('staff', Staff::getStaff());
- $this->assign('consumetype',$this->model::getconsumetype());
- return $this->view->fetch();
- }
- /**
- * 费用详情
- */
- public function detail($ids = null)
- {
- $row = $this->model->with(['staff', 'customer', 'followStaff'])->where([
- 'id' => $ids,
- ])->find();
- if (empty($row)) {
- $this->error(__('No Results were found'));
- }
- $row['detail']= ConsumeDetail::where(['consume_id'=>$ids])->select();
- $this->assign('flow', Flow::getstepdetail(Flow::CONSUME_STATUS, $ids));
- //标记通知已读
- Message::setRead(Message::CONSUME_TYPE, $ids, $this->_staff->id);
- //审批记录
- $this->assign('examine_record', ExamineRecord::getList(ExamineRecord::CONSUME_TYPE, $ids));
- $this->assign('row', $row);
- $this->assign('ids', $ids);
- return $this->view->fetch();
- }
- /**
- * 删除
- */
- public function del($ids = "")
- {
- if (!$this->request->isPost()) {
- $this->error(__("Invalid parameters"));
- }
- $ids = $ids ? $ids : $this->request->post("ids");
- $row = $this->model::where(['id' => $ids, 'check_status' => ['in', [0, 1, 3, 4, 5]]])->find();
- if (empty($row)) {
- $this->error('审核通过的费用不可删除');
- }
- $row = $this->model->get($ids);
- $this->modelValidate = true;
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $row->delete();
- $this->success();
- }
- /**
- * 交通费
- */
- public function clf() {
- return $this->view->fetch('clf');
- }
- /**
- * 其他
- */
- public function other() {
- return $this->view->fetch('other');
- }
- /**
- * 费用统计
- */
- public function consume_count() {
- $number=input('number');
- $this->success('请求成功','',['money'=>$this->model::getMileageMoney($number)]);
- }
- }
|