赛亿提成统计系统

Commission.php 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. namespace app\index\controller;
  3. use daswork\Controller;
  4. use daswork\lib\Config;
  5. use app\index\model\MonthPicker;
  6. use app\index\model\Commission as CommissionModel;
  7. use app\index\model\Company;
  8. class Commission extends Controller
  9. {
  10. public $maonth_picker;
  11. public $model;
  12. protected $params;
  13. public function __construct()
  14. {
  15. parent::__construct();
  16. $this->maonth_picker = new MonthPicker();
  17. $this->model = new CommissionModel();
  18. $this->params = escapeString($_POST);
  19. }
  20. public function index()
  21. {
  22. $slect_time = isset($_GET['select_time']) ? $_GET['select_time'] : '';
  23. if ($slect_time != '') {
  24. $this->maonth_picker->cur_month = $slect_time;
  25. }
  26. $this->assign('maonth_picker', $this->maonth_picker);
  27. $c_type = isset($_GET['c_type']) ? $_GET['c_type'] : '';
  28. if ($c_type != '') {
  29. $c_type = intval($c_type);
  30. }
  31. $this->assign('c_type', $c_type);
  32. $company = new Company();
  33. $data_company = $company->listByName();
  34. // var_dump($data_company);
  35. $this->assign('data_company', $data_company);
  36. $where = " where month='". $this->maonth_picker->cur_month . "' ";
  37. if ($c_type !=='') {
  38. $where .= " and type=$c_type ";
  39. }
  40. $where .= " order by id desc";
  41. $data = $this->model->list($where);
  42. array_walk($data, array($this,"handleData"));
  43. // var_dump($data);
  44. // exit;
  45. $this->assign('data', $data);
  46. $this->fetch();
  47. }
  48. public function handleData(&$value)
  49. {
  50. $value['price_rate'] = round($value['price'] / $value['base_price'], 4);
  51. switch ($value['type']) {
  52. case 1:
  53. if ($value['price_rate'] < 1.05) {
  54. $value['c_rate'] = 0.01;
  55. } elseif ($value['price_rate'] < 1.1) {
  56. $value['c_rate'] = 0.015;
  57. } else {
  58. $value['c_rate'] = 0.02;
  59. }
  60. $value['actual_value'] = $value['contract_value'] - $value['agency'];
  61. $value['c_money'] = ($value['actual_value'] - $value['shipping']) * $value['c_rate'];
  62. break;
  63. case 2:
  64. $value['c_rate'] = floor(((($value['price_rate'] - 1) / 0.1) * 0.01 + 0.01) * 100) / 100;
  65. $value['actual_value'] = $value['contract_value'] - $value['agency'];
  66. $value['c_money'] = ($value['actual_value'] - $value['shipping']) * $value['c_rate'];
  67. break;
  68. default:
  69. $value['c_rate'] = 0;
  70. $value['base_value'] = $value['amount'] * $value['base_price'];
  71. $value['total_profit'] = $value['contract_value'] - $value['agency'] - $value['base_value'] - $value['shipping'];
  72. break;
  73. }
  74. $value['actual_money'] = $value['receive_money'] + $value['period_balance'];
  75. $value['current_balance'] = $value['actual_money'] - $value['contract_value'];
  76. }
  77. public function info()
  78. {
  79. $id = isset($_GET['id']) ? $_GET['id'] : '';
  80. if ($id) {
  81. $data = $this->model->getOneById($id);
  82. $this->handleData($data);
  83. echo json_encode(['code'=>0, 'data'=>$data]);
  84. } else {
  85. echo json_encode(['code'=>1, 'msg'=>'id 不可为空']);
  86. }
  87. }
  88. public function perbalance()
  89. {
  90. $company = $this->params['company'];
  91. $sql = "select sum(receive_money - contract_value) as pb from commission where company='$company';" ;
  92. $sqlinitbalance = "select initial_balance from company where name='$company';";
  93. $result = $this->model->query($sql);
  94. $data = $result->fetchArray(SQLITE3_ASSOC);
  95. $result2 = $this->model->query($sqlinitbalance);
  96. $data2 = $result2->fetchArray(SQLITE3_ASSOC);
  97. $perbalance = $data['pb'];
  98. $initbalance = $data2['initial_balance'];
  99. echo json_encode(['code'=>0, 'data'=>$perbalance + $initbalance]);
  100. }
  101. public function save()
  102. {
  103. $id = $this->params['id'];
  104. $data = [
  105. 'id' => $id,
  106. 'month' => $this->params['month'],
  107. 'company' => $this->params['company'],
  108. 'contract_no' => $this->params['contract_no'],
  109. 'goods_category' => $this->params['goods_category'],
  110. 'goods_type' => $this->params['goods_type'],
  111. 'amount' => $this->params['amount'],
  112. 'price' => $this->params['price'],
  113. 'contract_value' => $this->params['contract_value'],
  114. 'receive_money' => $this->params['receive_money'],
  115. 'period_balance' => $this->params['period_balance'],
  116. 'agency' => $this->params['agency'],
  117. 'base_price' => $this->params['base_price'],
  118. 'shipping' => $this->params['shipping'],
  119. 'project' => $this->params['project'],
  120. 'type' => $this->params['type'],
  121. 'seller' => $this->params['seller'],
  122. 'remark' => $this->params['remark'],
  123. 'former_id' => $this->params['former_id']
  124. ];
  125. if ($id!=0) {
  126. $res = $this->model->updateById($data);
  127. } else {
  128. unset($data['id']);
  129. $res = $this->model->save($data);
  130. }
  131. if ($res===false) {
  132. echo json_encode(['code' => 1, "msg"=>$this->model->lastErrorMsg()]);
  133. } else {
  134. echo json_encode(['code' => 0, "msg"=>"操作成功"]);
  135. }
  136. }
  137. public function delete()
  138. {
  139. $params = escapeString($_POST);
  140. $id = $params['id'];
  141. $res = $this->model->deleteById($id);
  142. if ($res===false) {
  143. echo json_encode(['code' => 1, "msg"=>$this->model->lastErrorMsg()]);
  144. } else {
  145. echo json_encode(['code' => 0, "msg"=>"操作成功"]);
  146. }
  147. }
  148. }