123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- namespace app\index\controller;
- use daswork\Controller;
- use daswork\lib\Config;
- use app\index\model\MonthPicker;
- use app\index\model\Commission as CommissionModel;
- use app\index\model\Company;
- class Commission extends Controller
- {
- public $maonth_picker;
- public $model;
- protected $params;
- public function __construct()
- {
- parent::__construct();
- $this->maonth_picker = new MonthPicker();
- $this->model = new CommissionModel();
- $this->params = escapeString($_POST);
- }
- public function index()
- {
- $slect_time = isset($_GET['select_time']) ? $_GET['select_time'] : '';
-
- if ($slect_time != '') {
- $this->maonth_picker->cur_month = $slect_time;
- }
- $this->assign('maonth_picker', $this->maonth_picker);
- $c_type = isset($_GET['c_type']) ? $_GET['c_type'] : '';
- if ($c_type != '') {
- $c_type = intval($c_type);
- }
- $this->assign('c_type', $c_type);
- $company = new Company();
- $data_company = $company->listByName();
-
- $this->assign('data_company', $data_company);
- $where = " where month='". $this->maonth_picker->cur_month . "' ";
- if ($c_type !=='') {
- $where .= " and type=$c_type ";
- }
- $where .= " order by id desc";
- $data = $this->model->list($where);
- array_walk($data, array($this,"handleData"));
-
-
- $this->assign('data', $data);
- $this->fetch();
- }
- public function handleData(&$value)
- {
- $value['price_rate'] = round($value['price'] / $value['base_price'], 4);
- switch ($value['type']) {
- case 1:
- if ($value['price_rate'] < 1.05) {
- $value['c_rate'] = 0.01;
- } elseif ($value['price_rate'] < 1.1) {
- $value['c_rate'] = 0.015;
- } else {
- $value['c_rate'] = 0.02;
- }
- $value['actual_value'] = $value['contract_value'] - $value['agency'];
- $value['c_money'] = ($value['actual_value'] - $value['shipping']) * $value['c_rate'];
- break;
- case 2:
- $value['c_rate'] = floor(((($value['price_rate'] - 1) / 0.1) * 0.01 + 0.01) * 100) / 100;
- $value['actual_value'] = $value['contract_value'] - $value['agency'];
- $value['c_money'] = ($value['actual_value'] - $value['shipping']) * $value['c_rate'];
- break;
- default:
- $value['c_rate'] = 0;
- $value['base_value'] = $value['amount'] * $value['base_price'];
- $value['total_profit'] = $value['contract_value'] - $value['agency'] - $value['base_value'] - $value['shipping'];
- break;
- }
- $value['actual_money'] = $value['receive_money'] + $value['period_balance'];
- $value['current_balance'] = $value['actual_money'] - $value['contract_value'];
- }
- public function info()
- {
- $id = isset($_GET['id']) ? $_GET['id'] : '';
- if ($id) {
- $data = $this->model->getOneById($id);
- $this->handleData($data);
- echo json_encode(['code'=>0, 'data'=>$data]);
- } else {
- echo json_encode(['code'=>1, 'msg'=>'id 不可为空']);
- }
- }
- public function perbalance()
- {
- $company = $this->params['company'];
- $sql = "select sum(receive_money - contract_value) as pb from commission where company='$company';" ;
- $sqlinitbalance = "select initial_balance from company where name='$company';";
- $result = $this->model->query($sql);
- $data = $result->fetchArray(SQLITE3_ASSOC);
- $result2 = $this->model->query($sqlinitbalance);
- $data2 = $result2->fetchArray(SQLITE3_ASSOC);
- $perbalance = $data['pb'];
- $initbalance = $data2['initial_balance'];
- echo json_encode(['code'=>0, 'data'=>$perbalance + $initbalance]);
- }
- public function save()
- {
- $id = $this->params['id'];
- $data = [
- 'id' => $id,
- 'month' => $this->params['month'],
- 'company' => $this->params['company'],
- 'contract_no' => $this->params['contract_no'],
- 'goods_category' => $this->params['goods_category'],
- 'goods_type' => $this->params['goods_type'],
- 'amount' => $this->params['amount'],
- 'price' => $this->params['price'],
- 'contract_value' => $this->params['contract_value'],
- 'receive_money' => $this->params['receive_money'],
- 'period_balance' => $this->params['period_balance'],
- 'agency' => $this->params['agency'],
- 'base_price' => $this->params['base_price'],
- 'shipping' => $this->params['shipping'],
- 'project' => $this->params['project'],
- 'type' => $this->params['type'],
- 'seller' => $this->params['seller'],
- 'remark' => $this->params['remark'],
- 'former_id' => $this->params['former_id']
- ];
- if ($id!=0) {
- $res = $this->model->updateById($data);
- } else {
- unset($data['id']);
- $res = $this->model->save($data);
- }
- if ($res===false) {
- echo json_encode(['code' => 1, "msg"=>$this->model->lastErrorMsg()]);
- } else {
- echo json_encode(['code' => 0, "msg"=>"操作成功"]);
- }
- }
- public function delete()
- {
- $params = escapeString($_POST);
- $id = $params['id'];
- $res = $this->model->deleteById($id);
- if ($res===false) {
- echo json_encode(['code' => 1, "msg"=>$this->model->lastErrorMsg()]);
- } else {
- echo json_encode(['code' => 0, "msg"=>"操作成功"]);
- }
- }
- }
|