Finance.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. namespace app\admin\controller\qingdongams\finance;
  3. use addons\qingdongams\model\Consume as ConsumeModel;
  4. use addons\qingdongams\model\Customer as CustomerModel;
  5. use addons\qingdongams\model\JointFollow;
  6. use app\admin\controller\qingdongams\Base;
  7. use addons\qingdongams\model\Consume;
  8. use addons\qingdongams\model\ConsumeDetail;
  9. use addons\qingdongams\model\Customer;
  10. use addons\qingdongams\model\ExamineRecord;
  11. use addons\qingdongams\model\Staff;
  12. /**
  13. * 报销管理
  14. * @icon fa fa-user
  15. */
  16. class Finance extends Base {
  17. protected $relationSearch = true;
  18. protected $searchFields = 'id,title';
  19. /**
  20. * @var \addons\qingdongams\model\Consume
  21. */
  22. protected $model = null;
  23. public function _initialize() {
  24. parent::_initialize();
  25. $this->model = new Consume();
  26. }
  27. /**
  28. * 查看
  29. */
  30. public function index() {
  31. //设置过滤方法
  32. $this->request->filter(['strip_tags', 'trim']);
  33. if ($this->request->isAjax()) {
  34. //如果发送的来源是Selectpage,则转发到Selectpage
  35. if ($this->request->request('keyField')) {
  36. return $this->selectpage();
  37. }
  38. $condition['consume.check_status'] = ['in',[0,1,2,3]];
  39. $condition['consume.staff_id'] = ['in',Staff::getMyStaffIds()];
  40. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  41. $createtime = input('createtime','');
  42. $wheres = [];
  43. if($createtime && $createtime !='null '){
  44. $start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y")));
  45. $end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y")));
  46. $wheres['createtime'] = array('between',array(strtotime($start),strtotime($end)));
  47. }
  48. $model=new ConsumeDetail();
  49. $list = $model->with(['consume'])->where($where)
  50. ->where($condition)->where($wheres)->order('id desc')->paginate($limit);
  51. foreach ($list as $k=>&$v){
  52. $v['staff']=Staff::where(['id'=>$v['consume']['staff_id']])->field('id,img,name,post,mobile')->find();
  53. $v['customer']=Customer::where(['id'=>$v['consume']['customer_id']])->field('id,name,address')->find();
  54. $img = array_column($v['imgList'],'url');
  55. $v->imgs = implode(',',$img);
  56. }
  57. $result = array("total" => $list->total(), "rows" => $list->items());
  58. return json($result);
  59. }
  60. return $this->view->fetch();
  61. }
  62. //修改
  63. public function edit($ids = null) {
  64. $map['id'] = $ids;
  65. if ($this->request->isAjax()) {
  66. $data = $this->request->post('row/a');
  67. $result = $this->model->save($data, $map);
  68. if (!$result) {
  69. $this->error('修改失败');
  70. }
  71. $this->success('修改成功');
  72. }
  73. $data = $this->model->where($map)->find();
  74. $this->view->assign("row", $data);
  75. return $this->view->fetch();
  76. }
  77. //费用详情
  78. public function detail($ids = null) {
  79. // 基本信息
  80. $row = $this->model->where('id',$ids)->with(['staff','customer'])->find();
  81. if(empty($row)){
  82. $this->error('信息不存在');
  83. }
  84. $row['detail']= ConsumeDetail::where(['consume_id'=>$ids])->select();
  85. if ($row['check_status'] == 0 || $row['check_status'] == 1) {
  86. $row['is_examine'] = ExamineRecord::isExaminse(ExamineRecord::CONSUME_TYPE, $ids);
  87. } else {
  88. $row['is_examine'] = 0;
  89. }
  90. // 操作记录
  91. $operations = ExamineRecord::where('relation_id',$ids)->with(['checkStaff'])->select();
  92. $this->assign('ids',$ids);
  93. $this->assign('row',$row);
  94. $this->assign('operations',$operations);
  95. return $this->view->fetch();
  96. }
  97. // 处理参数
  98. public function operateParasm($data) {
  99. $detail_field = ['consume_type','consume_date','consume_money','end_mileage','mileage','file_ids','remark'];
  100. $list = [];
  101. foreach ($data as $k=>$v) {
  102. if(in_array($k,$detail_field)){
  103. foreach ($v as $key=>$val) {
  104. $list[$key][$k] = $val;
  105. }
  106. }
  107. }
  108. return array_values($list);
  109. }
  110. //获取联合跟进人
  111. public function getShowStaff($ids = null)
  112. {
  113. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  114. $list = \addons\qingdongams\model\JointFollow::where(['relation_type' => JointFollow::CONSUME_TYPE, 'relation_id' => $ids])->with(['staff'])->paginate($limit);
  115. $total = $list->total();
  116. $stfflist = $list->toArray()['data'];
  117. foreach ($stfflist as $k => $value){
  118. if ($value['roles'] == 1){
  119. $stfflist[$k]['is_edit'] = '负责人';
  120. }else{
  121. $stfflist[$k]['is_edit'] = $value['is_edit'] == 1?'读写':'只读';
  122. }
  123. $stfflist[$k]['roles'] = $value['roles'] == 1?'负责人':'团队成员';
  124. }
  125. $result = array("total" => $total, "rows" => $stfflist);
  126. return json($result);
  127. }
  128. public function set_team($ids = null){
  129. if ($this->request->isPost()) {
  130. $params = $this->request->post("row/a");
  131. if ($params) {
  132. $params = $this->preExcludeFields($params);
  133. $id = $params['id'];
  134. $staff = $params['staff'];
  135. $model = Consume::get($id);
  136. if (empty($model)) {
  137. $this->error('客户不存在');
  138. }
  139. foreach ($staff as $k=>$v) {
  140. if ($v['roles'] == 1) {//负责人
  141. $find = JointFollow::where(['relation_type' => JointFollow::CONSUME_TYPE,
  142. 'relation_id' => $id,
  143. 'roles' => 1
  144. ])->find();
  145. if($v['id'] != $find['staff_id']){
  146. JointFollow::where(['id'=>$find['id']])->update(['staff_id'=>$v['id']]);
  147. $model = Consume::get($id);
  148. }
  149. unset($staff[$k]);
  150. }
  151. }
  152. JointFollow::where(['relation_type' => JointFollow::CONSUME_TYPE,
  153. 'relation_id' => $id,
  154. 'roles' => 2
  155. ])->delete();
  156. $show_staff_id = [];
  157. $show_staff_id[] = $model->staff_id;
  158. $jointFollow = new JointFollow();
  159. $add = [];
  160. $find = JointFollow::where(['relation_type' => JointFollow::CONSUME_TYPE,
  161. 'relation_id' => $id,
  162. 'roles' => 1
  163. ])->find();
  164. foreach ($staff as $v) {
  165. if($v['id'] != $find['staff_id']) {
  166. $add[] = [
  167. 'relation_type' => $jointFollow::CONSUME_TYPE,
  168. 'relation_id' => $id,
  169. 'staff_id' => $v['id'],
  170. 'is_edit' => $v['is_edit'],
  171. 'roles' => 2,
  172. ];
  173. $show_staff_id[] = $v['id'];
  174. }
  175. }
  176. $jointFollow->saveAll($add);
  177. $model->save(['show_staff_ids' => implode(',', $show_staff_id)]);
  178. $this->success('编辑成功');
  179. }
  180. $this->error(__('Parameter %s can not be empty', ''));
  181. }
  182. $list = \addons\qingdongams\model\JointFollow::where(['relation_type' => JointFollow::CONSUME_TYPE, 'relation_id' => $ids,'roles' => 2])->with(['staff'])->select();
  183. $staffs = Staff::getList();
  184. $principal = \addons\qingdongams\model\JointFollow::where(['relation_type' => JointFollow::CONSUME_TYPE, 'relation_id' => $ids,'roles' => 1])->with(['staff'])->find();
  185. $this->assign('staffs', $staffs);
  186. $this->assign('principal', $principal);
  187. $this->assign('id',$ids);
  188. $this->assign('list', $list);
  189. return $this->view->fetch();
  190. }
  191. public function add_team($ids = null)
  192. {
  193. if ($this->request->isPost()) {
  194. $params = $this->request->post("row/a");
  195. if (!$params['staff_id']) {
  196. $this->error('请选择员工');
  197. }
  198. if ($params['is_edit'] == '') {
  199. $this->error('请选择权限');
  200. }
  201. $is_have = \addons\qingdongams\model\JointFollow::where(['relation_type' => JointFollow::CONSUME_TYPE, 'relation_id' => $ids, 'staff_id' => $params['staff_id']])->with(['staff'])->select();
  202. if ($is_have) {
  203. $this->error('该员工已存在团队中');
  204. }
  205. $info = Staff::get($params['staff_id'])->toArray();
  206. $info['is_edit'] = $params['is_edit'];
  207. $this->success('添加成功', '', $info);
  208. }
  209. $staffs = Staff::getList();
  210. $this->assign('staffs', $staffs);
  211. $this->assign('ids', $ids);
  212. return $this->view->fetch();
  213. }
  214. }