Consume.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. namespace app\admin\controller\qingdong\customer;
  3. use addons\qingdong\model\ExamineRecord;
  4. use addons\qingdong\model\File;
  5. use addons\qingdong\model\Flow;
  6. use addons\qingdong\model\Message;
  7. use addons\qingdong\model\Staff;
  8. use app\admin\controller\qingdong\Base;
  9. use addons\qingdong\model\ContractOther;
  10. use addons\qingdong\model\Form;
  11. use addons\qingdong\model\Contacts;
  12. use addons\qingdong\model\Customer;
  13. use addons\qingdong\model\OperationLog;
  14. use addons\qingdong\model\Record;
  15. use addons\qingdong\model\ContractFile;
  16. use think\Db;
  17. use think\Exception;
  18. /**
  19. * 费用管理
  20. * 操作文档:https://doc.fastadmin.net/qingdong
  21. * 软件介绍:https://www.fastadmin.net/store/qingdong.html
  22. * 售后微信:qingdong_crm
  23. */
  24. class Consume extends Base {
  25. protected $relationSearch = true;
  26. /**
  27. * @var \addons\qingdong\model\Consume
  28. */
  29. protected $model = null;
  30. public function _initialize() {
  31. parent::_initialize();
  32. $this->model = new \addons\qingdong\model\Consume;
  33. }
  34. /**
  35. * 查看
  36. */
  37. public function index() {
  38. //设置过滤方法
  39. $this->request->filter(['strip_tags', 'trim']);
  40. if ($this->request->isAjax()) {
  41. if ($this->request->request('keyField')) {
  42. return $this->selectpage();
  43. }
  44. //0:全部 1:我负责的 2:下属负责的
  45. $type = input('type',0);
  46. switch($type){
  47. case 1:
  48. $staff = Staff::info();
  49. $wheres['staff_id'] = $staff->id;
  50. break;
  51. case 2:
  52. $wheres['staff_id'] = array('in',Staff::getLowerStaffId());
  53. break;
  54. default:
  55. $wheres['staff_id'] = array('in',Staff::getMyStaffIds());
  56. break;
  57. }
  58. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  59. $list = $this->model->where($where)->where($wheres)->with(['customer','staff'])->order($sort, $order)->paginate($limit);
  60. $result = array("total" => $list->total(), "rows" => $list->items());
  61. return json($result);
  62. }
  63. return $this->view->fetch();
  64. }
  65. /**
  66. * 添加
  67. */
  68. public function add()
  69. {
  70. if ($this->request->isPost()) {
  71. $params = $this->request->post("row/a");
  72. if ($params) {
  73. $params = $this->preExcludeFields($params);
  74. // 表单验证
  75. if (($result = $this->qingdongValidate($params, 'Consume', 'create')) !== true) {
  76. $this->error($result);
  77. }
  78. $result = false;
  79. Db::startTrans();
  80. try {
  81. if(!empty($params['file_ids'])){
  82. $params['file_ids']=File::getId($params['file_ids']);
  83. }
  84. $result = $this->model::createConsume($params);
  85. Db::commit();
  86. } catch (Exception $e) {
  87. Db::rollback();
  88. $this->error($e->getMessage());
  89. }
  90. if ($result !== false) {
  91. $this->success('添加成功');
  92. } else {
  93. $this->error(__('No rows were inserted'));
  94. }
  95. }
  96. $this->error(__('Parameter %s can not be empty', ''));
  97. }
  98. $flow= Flow::getsteplist(Flow::CONSUME_STATUS);
  99. if (empty($flow)) {
  100. $this->error('无可用审批流,请联系管理员','qingdong/work/flow');
  101. }
  102. $customer_id=input('customer_id',null);
  103. $this->assign('customer_id',$customer_id);
  104. $this->assign('customer',Customer::get($customer_id));
  105. $this->assign('flow',$flow);
  106. $this->assign('staff', Staff::getStaff());
  107. return $this->view->fetch();
  108. }
  109. /**
  110. * 修改费用
  111. */
  112. public function edit($ids = null) {
  113. $map['id'] = $ids;
  114. if ($this->request->isAjax()) {
  115. $params = $this->request->post('row/a');
  116. $params = $this->preExcludeFields($params);
  117. $row = $this->model::where(['id' => $ids, 'check_status' => ['in', [0,1,3, 4,5]]])->find();
  118. if (empty($row)) {
  119. $this->error('审核通过的费用不可编辑');
  120. }
  121. Db::startTrans();
  122. try {
  123. $params['id'] = $ids;
  124. if(!empty($params['file_ids'])){
  125. $params['file_ids']=File::getId($params['file_ids']);
  126. }
  127. $result = $this->model::updateConsume($params);
  128. Db::commit();
  129. } catch (Exception $e) {
  130. Db::rollback();
  131. $this->error($e->getMessage());
  132. }
  133. if ($result !== false) {
  134. $this->success('修改成功');
  135. } else {
  136. $this->error('修改失败');
  137. }
  138. }
  139. $row = $this->model->where($map)->with(['customer'])->find();
  140. $customers=Customer::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->column('name','id');
  141. if($row['file_ids']){
  142. $wheres['id']=array('in',$row['file_ids']);
  143. $file = File::where($wheres)->column('file_path');
  144. $row['file_ids'] = implode(',',$file);
  145. }
  146. $flow= Flow::getsteplist(Flow::CONSUME_STATUS);
  147. if (empty($flow)) {
  148. $this->error('无可用审批流,请联系管理员','qingdong/work/flow');
  149. }
  150. $this->assign('flow',$flow);
  151. $this->view->assign("row", $row);
  152. $this->assign('customer', $customers);
  153. $this->assign('staff', Staff::getStaff());
  154. $this->assign('form_data', Form::getDataValue('contract'));
  155. return $this->view->fetch();
  156. }
  157. /**
  158. * 费用详情
  159. */
  160. public function detail($ids = null)
  161. {
  162. $row = $this->model->with(['staff','customer', 'followStaff'])->where([
  163. 'id' => $ids,
  164. ])->find();
  165. if (empty($row)) {
  166. $this->error(__('No Results were found'));
  167. }
  168. $this->assign('flow',Flow::getstepdetail(Flow::CONSUME_STATUS,$ids));
  169. //标记通知已读
  170. Message::setRead(Message::CONSUME_TYPE, $ids, $this->_staff->id);
  171. //审批记录
  172. $this->assign('examine_record', ExamineRecord::getList(ExamineRecord::CONSUME_TYPE,$ids));
  173. $this->assign('row', $row);
  174. $this->assign('ids', $ids);
  175. return $this->view->fetch();
  176. }
  177. /**
  178. * 删除
  179. */
  180. public function del($ids = "") {
  181. if (!$this->request->isPost()) {
  182. $this->error(__("Invalid parameters"));
  183. }
  184. $ids = $ids ? $ids : $this->request->post("ids");
  185. $row = $this->model::where(['id' => $ids, 'check_status' => ['in', [0,1,3, 4,5]]])->find();
  186. if (empty($row)) {
  187. $this->error('审核通过的费用不可删除');
  188. }
  189. $row = $this->model->get($ids);
  190. $this->modelValidate = true;
  191. if (!$row) {
  192. $this->error(__('No Results were found'));
  193. }
  194. $row->delete();
  195. $this->success();
  196. }
  197. }