You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

577 lines
20 KiB

  1. <?php
  2. /**
  3. * 财务应收管理控制器
  4. * Created by PhpStorm.
  5. * User: admin
  6. * Date: 2017/5/31
  7. * Time: 9:15
  8. */
  9. namespace backend\modules\zzcs\controllers;
  10. use backend\modules\zzcs\models\BaseSupplier;
  11. use backend\modules\zzcs\service\Gathering;
  12. use backend\modules\zzcs\service\Payment;
  13. use yii\db\Exception;
  14. use yii\web\Controller;
  15. use backend\modules\zzcs\models\BaseUser;
  16. use Yii;
  17. class GatheringController extends Controller
  18. {
  19. public $layout = '@backend/modules/zzcs/views/layouts/zzcs';
  20. public $enableCsrfValidation = false;
  21. public $service = null;
  22. /**
  23. * Des:获取service类初始化
  24. * Name: service
  25. * @return Gathering
  26. * @author 倪宗锋
  27. */
  28. public function service()
  29. {
  30. if ($this->service == null) {
  31. $this->service = new Gathering();
  32. }
  33. return $this->service;
  34. }
  35. /**
  36. * Des:管理页面
  37. * Name: actionCopeManager
  38. * @return string
  39. * @author 倪宗锋
  40. */
  41. public function actionReceivableManager()
  42. {
  43. // 获取main_corp_id
  44. $user_id = Yii::$app->request->cookies->getValue('user_id', 2);
  45. $model_user = new BaseUser();
  46. $user_info = $model_user->getUserInfo($user_id);
  47. $data['main_corp_id'] = $user_info[0]["MAIN_CORP_ID"];
  48. // 获取渠道商
  49. $base_supplier = new BaseSupplier();
  50. $result = $base_supplier->getChannelList();
  51. $data['channel_list'] = $result;
  52. // 获取列表页
  53. $start_date = date('Y-m-01 00:00:00');
  54. $end_date = date('Y-m-d 23:59:59', strtotime(date('Y-m-1') . " +1 month -1 day"));
  55. $param = $this->service()->getGetParam();//获取参数 通过get方式
  56. if (empty($param['date_type'])) {
  57. $param['date_type'] = 1;
  58. }
  59. if (empty($param['start_date'])) {
  60. $param['start_date'] = $start_date;
  61. $param['end_date'] = $end_date;
  62. }
  63. $getWhere = $this->service()->getWhere($param);//获取查询条件
  64. $result = $this->service()->getTotal($getWhere);//获取统计数据
  65. $total_row = $result['page']['total_count'];
  66. $total_page = $result['page']['total_page'];
  67. $page_size = $getWhere['param']['page_size'];
  68. $current_page = $getWhere['param']['current_page'];
  69. $order_list = $this->service()->getList($getWhere);//获取列表
  70. $data['list'] = $order_list;
  71. $page_size_arr = [10=>10,50=>50, 100=>100,'all'=>$total_row];
  72. $page_arr = $this->service()->getPage($total_row, $page_size, $current_page);
  73. $page = [
  74. 'page_size' => $page_size,
  75. 'current_page' => $current_page,
  76. 'total_row' => $total_row,
  77. 'total_page' => $total_page
  78. ];
  79. $data['page_arr'] = $page_arr;
  80. $data['page'] = $page;
  81. $data['page_size'] = $page_size;
  82. $data['page_size_arr'] = $page_size_arr;
  83. $data['sum_info']=$result['sum_info'];
  84. return $this->render('receivable_management_list', $data);
  85. }
  86. /**
  87. * Function Description:账单界面
  88. * Function Name: actionReceivableAccount
  89. *
  90. * @return string
  91. * @throws Exception
  92. *
  93. * @author 李健
  94. */
  95. public function actionReceivableAccount()
  96. {
  97. // 获取渠道商
  98. $data['channel_list'] = $this->service()->getChannel();
  99. // 获取列表
  100. $param = array(
  101. 'current_page' => Yii::$app->request->get('current_page', '1'),//当前页
  102. 'page_size' => Yii::$app->request->get('page_size', '10'),//每页展示条数
  103. 'org_id' => Yii::$app->request->get('org_id', ''),//供应商ID
  104. 'batch_id' => Yii::$app->request->get('batch_id', ''),//对账单号
  105. 'status' => Yii::$app->request->get('status', ''),//对账状态1待核对,2待结算,3已结算,4已取消
  106. );
  107. $user_id = Yii::$app->request->cookies->getValue('user_id', 2);
  108. $model_user = new BaseUser();
  109. $user_info = $model_user->getUserInfo($user_id);
  110. $param["main_corp_id"] = $user_info[0]["MAIN_CORP_ID"];
  111. $getList = $this->service()->getBalance($param);
  112. // 分页信息
  113. $current_page = $param['current_page'];
  114. $page_size = $param['page_size'];
  115. $total_row = $getList['page']['total_count'];
  116. $total_page = $getList['page']['total_page'];
  117. $data['list'] = $getList['order_list'];
  118. $page_size_arr = [10, 20, 30, 50, 100];
  119. $page_arr = $this->service()->getPage($total_row, $page_size, $current_page);
  120. $page = [
  121. 'page_size' => $page_size,
  122. 'current_page' => $current_page,
  123. 'total_row' => $total_row,
  124. 'total_page' => $total_page
  125. ];
  126. $data['page_arr'] = $page_arr;
  127. $data['page'] = $page;
  128. $data['page_size'] = $page_size;
  129. $data['page_size_arr'] = $page_size_arr;
  130. return $this->render('receivable_account_statement',$data);
  131. }
  132. /**
  133. * Des:获取列表
  134. * Name: actionGetList
  135. * @return string
  136. * @author 倪宗锋
  137. */
  138. public function actionGetList()
  139. {
  140. $param = $this->service()->getParam();//获取参数
  141. $getWhere = $this->service()->getWhere($param);//获取查询条件
  142. try {
  143. if ($getWhere['param']['current_page'] == 1) {//第一页时才获取统计数据
  144. $data = $this->service()->getTotal($getWhere);//获取统计数据
  145. $data['page']['page_size'] = $getWhere['param']['page_size'];
  146. $data['page']['current_page'] = $getWhere['param']['current_page'];
  147. }
  148. $data['order_list'] = $this->service()->getList($getWhere);//获取列表
  149. } catch (\Exception $e) {
  150. $json['code'] = '1';
  151. $json['info'] = '获取列表失败';
  152. return json_encode($json);
  153. }
  154. $json['code'] = '0';
  155. $json['info'] = '获取列表成功';
  156. $json['data'] = $data;
  157. return json_encode($json);
  158. }
  159. /**
  160. * Des:关账
  161. * Name: actionClosesAmount
  162. * @return string
  163. * @author 倪宗锋
  164. */
  165. public function actionClosesAmount()
  166. {
  167. $param = $this->service()->getParam();//获取参数
  168. $getWhere = $this->service()->getWhere($param);//获取查询条件
  169. $checkFlag = $this->service()->checkClosesAmount($getWhere);//校验是否可以关账
  170. if ($checkFlag == false) {
  171. $json['code'] = '1';
  172. $json['info'] = '关账失败!所选订单中有非待结算状态的订单!';
  173. return json_encode($json);
  174. }
  175. $user_id = Yii::$app->request->cookies->getValue('user_id', 2);
  176. $model_user = new BaseUser();
  177. $user_info = $model_user->getUserInfo($user_id);
  178. $getWhere["main_corp_id"] = $user_info[0]["MAIN_CORP_ID"];
  179. $closeFlag = $this->service()->closesAmount($getWhere);//执行关账操作
  180. if ($closeFlag == false) {
  181. $json['code'] = '1';
  182. $json['info'] = '关账失败!数据处理失败!';
  183. return json_encode($json);
  184. }
  185. $json['code'] = '0';
  186. $json['info'] = '关账成功!';
  187. return json_encode($json);
  188. }
  189. /**
  190. * Function Description:关账
  191. * Function Name: actionCloseByOrderId
  192. *
  193. * @return string
  194. * @throws Exception
  195. *
  196. * @author 李健
  197. */
  198. public function actionCloseByOrderId()
  199. {
  200. $str = trim(Yii::$app->request->post('order_id_str', ''), ',');
  201. $res = $this->service()->closeByOrderId($str);
  202. if ($res == false) {
  203. $json['code'] = '1';
  204. $json['info'] = '关账失败!数据处理失败!';
  205. return json_encode($json);
  206. }
  207. $json['code'] = '0';
  208. $json['info'] = '关账成功!';
  209. return json_encode($json);
  210. }
  211. /**
  212. * Des:生成对账单
  213. * Name: ActionAddBalance
  214. * @return string
  215. * @throws Exception
  216. * @author 倪宗锋
  217. */
  218. public function actionAddBalance()
  219. {
  220. $param = $this->service()->getParam();//获取参数
  221. $getWhere = $this->service()->getWhere($param);//获取查询条件
  222. $checkFlag = $this->service()->checkIsAllCloses($getWhere);//检测是否所有记录状态都是关账状态
  223. if ($checkFlag == false) {
  224. $json['code'] = '1';
  225. $json['info'] = '生成对账单失败!所选订单中有非已关账状态的订单!';
  226. return json_encode($json);
  227. }
  228. $user_id = Yii::$app->request->cookies->getValue('user_id', 2);
  229. $model_user = new BaseUser();
  230. $user_info = $model_user->getUserInfo($user_id);
  231. $getWhere["main_corp_id"] = $user_info[0]["MAIN_CORP_ID"];
  232. $addFlag = $this->service()->addBalance($getWhere);//生成对账单
  233. if ($addFlag == false) {
  234. $json['code'] = '1';
  235. $json['info'] = '生成对账单失败!数据处理失败!';
  236. return json_encode($json);
  237. }
  238. $json['code'] = '0';
  239. $json['info'] = '生成对账单成功!';
  240. return json_encode($json);
  241. }
  242. /**
  243. * Function Description:生成对账单
  244. * Function Name: actionAddBalanceByOrderId
  245. *
  246. * @return string
  247. * @throws Exception
  248. *
  249. * @author 李健
  250. */
  251. public function actionAddBalanceByOrderId()
  252. {
  253. $str = trim(Yii::$app->request->post('order_id_str', ''), ',');
  254. $start_date = Yii::$app->request->post('start_date', '');
  255. $end_date = Yii::$app->request->post('end_date', '');
  256. $user_id = Yii::$app->request->cookies->getValue('user_id', 2);
  257. $model_user = new BaseUser();
  258. $user_info = $model_user->getUserInfo($user_id);
  259. $main_corp_id = $user_info[0]["MAIN_CORP_ID"];
  260. $addFlag = $this->service()->addBalanceByOrderId($str, $start_date, $end_date, $main_corp_id);//生成对账单
  261. if ($addFlag == false) {
  262. $json['code'] = '1';
  263. $json['info'] = '生成对账单失败!数据处理失败!';
  264. return json_encode($json);
  265. }
  266. $json['code'] = '0';
  267. $json['info'] = '生成对账单成功!';
  268. return json_encode($json);
  269. }
  270. /**
  271. * Des:取消关账
  272. * Name: actionCancelCloses
  273. * @return string
  274. * @throws Exception
  275. * @author 倪宗锋
  276. */
  277. public function actionCancelCloses()
  278. {
  279. $param = $this->service()->getParam();//获取参数
  280. $getWhere = $this->service()->getWhere($param);//获取查询条件
  281. $checkFlag = $this->service()->checkIsAllCloses($getWhere);//检测是否所有记录状态都是关账状态
  282. if ($checkFlag == false) {
  283. $json['code'] = '1';
  284. $json['info'] = '生成对账单失败!所选订单中有非已关账状态的订单!';
  285. return json_encode($json);
  286. }
  287. $addFlag = $this->service()->cancelCloses($getWhere);//执行取消关账操作
  288. if ($addFlag == false) {
  289. $json['code'] = '1';
  290. $json['info'] = '生成对账单失败!数据处理失败!';
  291. return json_encode($json);
  292. }
  293. $json['code'] = '0';
  294. $json['info'] = '生成对账单成功!';
  295. return json_encode($json);
  296. }
  297. /**
  298. * Function Description:取消关账通过id
  299. * Function Name: actionCancelByOrderId
  300. *
  301. * @return string
  302. * @throws Exception
  303. *
  304. * @author 李健
  305. */
  306. public function actionCancelByOrderId()
  307. {
  308. $str = trim(Yii::$app->request->post('order_id_str', ''), ',');
  309. $res = $this->service()->cancelByOrderId($str);
  310. if ($res == false) {
  311. $json['code'] = '1';
  312. $json['info'] = '取消关账失败!数据处理失败!';
  313. return json_encode($json);
  314. }
  315. $json['code'] = '0';
  316. $json['info'] = '生成对账单成功!';
  317. return json_encode($json);
  318. }
  319. /**
  320. * Des:获取对账单列表
  321. * Name: actionGetBalance
  322. * @return string
  323. * @throws Exception
  324. * @author 倪宗锋
  325. */
  326. public function actionGetBalance()
  327. {
  328. $param = array(
  329. 'current_page' => Yii::$app->request->post('current_page', ''),//当前页
  330. 'page_size' => Yii::$app->request->post('page_size', ''),//每页展示条数
  331. 'org_id' => Yii::$app->request->post('org_id', ''),//供应商ID
  332. 'batch_id' => Yii::$app->request->post('batch_id', ''),//对账单号
  333. 'status' => Yii::$app->request->post('status', ''),//对账状态1待核对,2待结算,3已结算,4已取消
  334. );
  335. $user_id = Yii::$app->request->cookies->getValue('user_id', 2);
  336. $model_user = new BaseUser();
  337. $user_info = $model_user->getUserInfo($user_id);
  338. $param["main_corp_id"] = $user_info[0]["MAIN_CORP_ID"];
  339. $getList = $this->service()->getBalance($param);
  340. $json['code'] = '0';
  341. $json['info'] = '获取列表成功';
  342. $getList['page']['page_size'] = $param['page_size'];
  343. $getList['page']['current_page'] = $param['current_page'];
  344. $json['data'] = $getList;
  345. return json_encode($json);
  346. }
  347. /**
  348. * Des:取消对账
  349. * Name: cancelBalance
  350. * @return string
  351. * @throws Exception
  352. * @author 倪宗锋
  353. */
  354. public function actionCancelBalance()
  355. {
  356. $id = Yii::$app->request->post('id', '');
  357. //校验对账单状态
  358. $flag = $this->service()->checkBalanceStatus($id, array(1));
  359. if ($flag == false) {
  360. $json['code'] = '2';
  361. $json['info'] = '失败!待核对的账单才可以执行取消操作!';
  362. return json_encode($json);
  363. }
  364. $flag = $this->service()->cancelBalance($id);
  365. if ($flag == false) {
  366. $json['code'] = '2';
  367. $json['info'] = '取消对账失败!';
  368. return json_encode($json);
  369. }
  370. $json['code'] = '0';
  371. $json['info'] = '取消对账成功';
  372. return json_encode($json);
  373. }
  374. /**
  375. * Des:确认对账单
  376. * Name: actionConfirmedBalance
  377. * @return string
  378. * @throws Exception
  379. * @author 倪宗锋
  380. */
  381. public function actionConfirmedBalance()
  382. {
  383. $id = Yii::$app->request->post('id', '');
  384. //校验对账单状态
  385. $flag = $this->service()->checkBalanceStatus($id, array(1));
  386. if ($flag == false) {
  387. $json['code'] = '2';
  388. $json['info'] = '失败!待核对的账单才可以确认核对!';
  389. return json_encode($json);
  390. }
  391. $flag = $this->service()->confirmedBalance($id);
  392. if ($flag == false) {
  393. $json['code'] = '2';
  394. $json['info'] = '确认对账单状态失败!';
  395. return json_encode($json);
  396. }
  397. $json['code'] = '0';
  398. $json['info'] = '确认对账单状态成功';
  399. return json_encode($json);
  400. }
  401. /**
  402. * Des:确认结算
  403. * Name: actionBalancing
  404. * @return string
  405. * @throws Exception
  406. * @author 倪宗锋
  407. */
  408. public function actionBalancing()
  409. {
  410. $id = Yii::$app->request->post('id', '');
  411. //校验对账单状态
  412. $flag = $this->service()->checkBalanceStatus($id, array(2));
  413. if ($flag == false) {
  414. $json['code'] = '2';
  415. $json['info'] = '失败!已核对的账单才可以结算!';
  416. return $json;
  417. }
  418. $flag = $this->service()->balancing($id);
  419. if ($flag == false) {
  420. $json['code'] = '2';
  421. $json['info'] = '结算订单失败!system error';
  422. return json_encode($json);
  423. }
  424. $json['code'] = '0';
  425. $json['info'] = '结算订单成功';
  426. return json_encode($json);
  427. }
  428. /**
  429. * Des:导出excel
  430. * Name: excelBalance
  431. * @return string
  432. * @author 倪宗锋
  433. */
  434. public function actionExcelBalance()
  435. {
  436. $id = Yii::$app->request->get('id', '');
  437. $info = $this->service()->getAccountInfo($id);
  438. if ($info == false) {
  439. echo '导出excel失败!';
  440. die;
  441. }
  442. $list = $this->service()->getListForExcel($info);
  443. /**======生成excel=========**/
  444. ob_clean();
  445. $fileName = '【' . $info['org_name'] . '】应收账单-' . $info['start_date'] . '~' . $info['end_date'] . '.csv';
  446. $fileName = iconv("utf-8", "gb2312", $fileName);
  447. header("Content-type:text/csv");
  448. header("Content-Disposition:attachment;filename=" . $fileName);
  449. header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
  450. header('Expires:0');
  451. header('Pragma:public');
  452. $data = '';
  453. foreach ($list as $key => $val) {
  454. if ($key == 0) {
  455. $data .= implode(',', array_keys($val)) . "\n";
  456. }
  457. $data .= '"' . implode('","', array_values($val)) . "\"\n";
  458. }
  459. $data = chr(0xEF) . chr(0xBB) . chr(0xBF) . $data;
  460. echo $data;
  461. return '';
  462. }
  463. /**
  464. * Function Description:未关账前导出
  465. * Function Name: actionBeforeExcelBalance
  466. *
  467. *
  468. * @author LUOCJ
  469. */
  470. public function actionBeforeExcelBalance()
  471. {
  472. $param = $this->service()->getGetParam();//获取参数
  473. $getWhere = $this->service()->getWhere($param);//获取查询条件
  474. $list = $this->service()->getList($getWhere, 1);//获取列表
  475. $fin_list = [];
  476. foreach ($list as $k => $v) {
  477. $fin_list[$k]['order_id'] = $v['order_id'];
  478. $fin_list[$k]['cus_name'] = $v['cus_name'];
  479. $fin_list[$k]['outside_order_no'] = $v['outside_order_no'];
  480. $fin_list[$k]['run_date'] = $v['run_date'];
  481. $fin_list[$k]['create_time'] = $v['create_time'];
  482. $fin_list[$k]['parent_prod_name'] = $v['parent_prod_name'];
  483. $fin_list[$k]['prod_type_des'] = $v['prod_type_des'];
  484. $fin_list[$k]['prodName'] = $v['prodName'];
  485. $fin_list[$k]['prodNum'] = $v['prodNum'];
  486. $fin_list[$k]['order_price'] = $v['order_price'];
  487. $fin_list[$k]['reparations_price'] = $v['reparations_price'];
  488. $fin_list[$k]['total_commission'] = $v['total_commission'];
  489. $fin_list[$k]['supplier_name'] = $v['supplier_name'];
  490. $fin_list[$k]['prodNum'] = $v['prodNum'];
  491. }
  492. $title = ['订单ID', '顾客姓名', '渠道订单ID', '出游时间', '预订时间', '产品名称', '产品类型', '房型/票种', '间夜/票数', '订单金额', '佣金', '赔款', '供应商'];
  493. $file_name = '应收账单';
  494. /**======生成excel=========**/
  495. Payment::to_excel($file_name, $title, $fin_list);
  496. }
  497. /**
  498. * Function Description:校验订单结算状态
  499. * Function Name: actionCheckId
  500. *
  501. * @return string
  502. * @throws Exception
  503. *
  504. * @author 李健
  505. */
  506. public function actionCheckId()
  507. {
  508. $type = Yii::$app->request->post('type', '');
  509. $id = Yii::$app->request->post('id', '');
  510. $status = Yii::$app->request->post('status', '');
  511. $order_ids = explode(',', trim($id, ','));
  512. $str_id = '';
  513. foreach ($order_ids as $order_id) {
  514. $res = $this->service()->getStatus($order_id);
  515. if(!$res){
  516. if($type==1){
  517. continue;
  518. }
  519. $str_id .= $order_id . ',';
  520. }
  521. if ($type == 1) {
  522. if ($res[$status] != 1) {
  523. $str_id .= $res['order_id'] . ', ';
  524. }
  525. } elseif ($type == 2 || $type == 3) {
  526. if ($res[$status] != 2) {
  527. $str_id .= $res['order_id'] . ',';
  528. }
  529. }
  530. }
  531. if ($str_id != '') {
  532. $str_id = rtrim($str_id, ', ');
  533. $json['code'] = 1;
  534. $json['info'] = ' 订单编号为' . $str_id . '的数据结算状态异常!请重新选择';
  535. } else {
  536. $json['code'] = 0;
  537. $json['info'] = '';
  538. }
  539. return json_encode($json);
  540. }
  541. }