huwhois 4 years ago
parent
commit
b470f8b1d2

+ 30 - 2
app/common.php

@ -2,7 +2,7 @@
2 2
// 应用公共文件
3 3
4 4
/**
5
 * 格式化金额 将分为单位的金额以元输出
5
 * 格式化金额 将分为单位的金额以元输出 千分位分割
6 6
 * @param $price
7 7
 * @return string
8 8
 */
@ -13,4 +13,32 @@ function format_money($price)
13 13
    }
14 14
15 15
    return number_format(bcdiv($price, 100, 2), 2);
16
}
16
}
17
18
/**
19
 * 将元为单位的金额转化为分
20
 * @param $price
21
 * @return int
22
 */
23
function int_money($price)
24
{
25
    if (!is_numeric($price)) {
26
        $price = 0;
27
    }
28
    
29
    return intval(bcmul($price, 100));
30
}
31
32
/**
33
 * 格式化金额 将分为单位的金额以元输出
34
 * @param $price
35
 * @return string
36
 */
37
function number_money($price)
38
{
39
    if (!is_numeric($price)) {
40
        $price = 0;
41
    }
42
43
    return bcdiv($price, 100, 2);
44
}

+ 298 - 0
app/controller/Commission.php

@ -0,0 +1,298 @@
1
<?php
2
namespace app\controller;
3
4
use think\App;
5
use think\facade\View;
6
use app\model\Order as OrderModel;
7
use app\model\Commission as CommissionModel;
8
use app\model\OrderItem as OrderItemModel;
9
use app\model\OrderDetails as OrderDetailsModel;
10
use app\model\Department as DepartmentModel;
11
use think\facade\Db;
12
use app\model\Company as CompanyModel;
13
use app\model\Seller as SellerModel;
14
use think\facade\Env;
15
16
class Commission extends Base
17
{
18
    protected $model;
19
    protected $orderModel;
20
    protected $itemModel;
21
    protected $detailsModel;
22
    // ; 提成比例 单位千分
23
    // 销售
24
    // 一般
25
    protected $general_ratio;
26
    // 特批提成的三种比例 10, 15, 20 
27
    protected $special_a;
28
    protected $special_b;
29
    protected $special_c;
30
    // 特批2提成比例另计
31
    protected $special_d;
32
    protected $special_e;
33
    // 后勤
34
    // 一般
35
    protected $general_logistics;
36
    // 特批
37
    protected $special_logistics;
38
    // 部门
39
    // 一般
40
    protected $general_deparment;
41
    // 特批
42
    protected $special_deparment;
43
44
    public function __construct(App $app)
45
    {
46
        parent::__construct($app);
47
        $this->model = new CommissionModel();
48
        $this->orderModel = new OrderModel();
49
        $this->itemModel = new OrderItemModel();
50
        $this->detailsModel = new OrderDetailsModel();
51
        $this->general_ratio= Env::get('commission.general_ratio', 250);
52
        $this->special_a= Env::get('commission.special_a', 10);
53
        $this->special_b= Env::get('commission.special_b', 15);
54
        $this->special_c= Env::get('commission.special_c', 20);
55
        $this->special_d= Env::get('commission.special_d', 10);
56
        $this->special_e= Env::get('commission.special_e', 10);
57
        $this->general_logistics= Env::get('commission.general_logistics', 50);
58
        $this->special_logistics= Env::get('commission.special_logistics', 2);
59
        $this->general_deparment= Env::get('commission.general_deparment', 14);
60
        $this->special_deparment= Env::get('commission.special_deparment', 1.4);
61
    }
62
63
    public function year()
64
    {
65
        $init_year = Env::get('INIT_YEAR');
66
        $current_year = date("Y");
67
68
        return View::fetch('',[
69
            'init_year' => $init_year,
70
            'current_year' => $current_year,
71
        ]);
72
    }
73
74
75
    public function index($year=0, $month=0)
76
    {
77
        $year = $year ? : date("Y");
78
        $month = $month ? : date("n");  // 不带前导0的月份
79
        $map = [
80
            ['year', '=', $year],
81
            ['month', '=', $month]
82
        ];
83
84
        $list = [];
85
        $data = $this->model->where($map)->field('seller_name,seller_id,sum(general_money) as general_money, sum(special_money) as special_money,department_id,remark')
86
            ->group('seller_id')->select();
87
        $list = $data->toArray();
88
        foreach ($list as &$value) {
89
            $value['profit'] = intval(bcdiv($value['general_money'] * 1000, $this->general_ratio));
90
            $value['general_ratio'] = bcdiv($this->general_ratio, 1000, 4) * 100 ."%";
91
            $value['total_special_money'] = $value['special_money'];
92
            $value['special_ratio'] =  '100%';
93
        }
94
        unset($value); // 避免影响下面的$value
95
    
96
        // 后倾
97
        $logistics['seller_name'] = '后勤';
98
        $total_general_money = $this->model->where($map)->sum('general_money');
99
        $total_special_money = $this->model->where($map)->sum('special_money');
100
        $logistics['profit'] =  intval(bcdiv($total_general_money * 1000, $this->general_ratio));
101
        $logistics['general_ratio'] = bcdiv($this->general_logistics, 1000, 4) * 100 ."%";
102
        $logistics['general_money'] = intval(bcdiv(bcmul($this->general_logistics,  $total_general_money), $this->general_ratio));
103
        $logistics['total_special_money'] = $total_special_money;
104
        $logistics['special_ratio'] =  bcdiv($this->special_logistics, 1000, 5) * 100 .'%';
105
        $logistics['special_money'] = intval(bcmul($this->special_logistics,  $total_special_money));
106
        $logistics['remark'] = "";
107
        $list[] =  $logistics;
108
       
109
        // var_dump($list);
110
        // 部门主管提成
111
        $departements = DepartmentModel::select();
112
        foreach ($departements as $value) {
113
            $arr = [];
114
            $arr['seller_name'] = $value->director . '月度' ;
115
            $arr['general_money'] = 0;
116
            $arr['special_money'] = 0;
117
            foreach ($data as $key => $val) {
118
                if ($val->department_id == $value->id) {
119
                    $arr['general_money'] += $val->general_money;
120
                    $arr['special_money'] += $val->special_money;
121
                }
122
            }
123
            $arr['profit'] = intval(bcdiv($arr['general_money'] * 1000, $this->general_ratio)) ;
124
            $arr['general_ratio'] = bcdiv($this->general_deparment, 1000, 4) * 100 .'%';
125
            $arr['general_money']  = intval(bcdiv(bcmul($this->general_deparment, $arr['general_money']), $this->general_ratio));
126
            $arr['total_special_money'] = $arr['special_money'];
127
            $arr['special_ratio'] = bcdiv($this->special_deparment, 1000, 5) * 100 .'%';
128
            $arr['special_money'] = intval(bcmul($this->special_deparment, $arr['special_money']));
129
            $arr['remark'] = "";
130
131
            $list[] = $arr;
132
        }
133
        // var_dump($total_general_money);
134
        // var_dump($total_special_money);
135
        // var_dump($list);
136
        // exit;
137
        return View::fetch('',[
138
            'year' => $year,
139
            'month' => $month,
140
            'list' => $list,
141
            'total_general_money' => $total_general_money,
142
            'total_special_money' => $total_special_money,
143
        ]);
144
    }
145
146
    public function lists($year=0, $month=0, $key="")
147
    {
148
        if (!$year || !$month) {
149
            throw new \think\exception\HttpException(404, '页面参数不正确');  
150
        }
151
        
152
        $map = [
153
            ['year', '=', $year],
154
            ['month', '=', $month]
155
        ];
156
157
        if ($key) {
158
            $map[] = ['company_name','LIKE', '%'.$key.'%'];
159
        }
160
161
        $list = $this->model->where($map)->order('id')->select();
162
   
163
        $total_general_money = $this->model->where($map)->sum('general_money');
164
        $total_special_money = $this->model->where($map)->sum('special_money');
165
166
        return View::fetch('',[
167
            'year' => $year,
168
            'month' => $month,
169
            'key' => $key,
170
            'list' => $list,
171
            'total_general_money' =>$total_general_money,
172
            'total_special_money' =>$total_special_money,
173
        ]);
174
    }
175
176
    public function info($id=0)
177
    {
178
        
179
    }
180
181
    public function save()
182
    {
183
        if ($this->request->isPost()) {
184
            $param = $this->request->param();
185
186
            try {
187
                if ($param['id']) {
188
                    $commission = $this->model->find(intval($param['id']));
189
                } else {
190
                    $commission = new CommissionModel();
191
                    $commission->create_time = time();
192
                }
193
194
                $commission->order_id = intval($param['order_id']);
195
                $commission->no = $param['no'];
196
                $commission->contract_no = $param['contract_no'];               
197
                $commission->company_id = intval($param['company_id']);
198
                $commission->company_name = $param['company_name'];
199
                $commission->seller_id = intval($param['seller_id']);
200
                $commission->seller_name = $param['seller_name'];
201
                $commission->department_id = intval($param['department_id']);
202
                $commission->department_name = $param['department_name'];
203
                $commission->general_money = int_money($param['general_money']);
204
                $commission->special_money = int_money($param['special_money']);
205
                $commission->time = $param['time'];
206
                $commission->remark = $param['remark'];
207
                $commission->year = date('Y',strtotime($param['time']));
208
                $commission->month = date('n',strtotime($param['time']));
209
                
210
                $commission->save();
211
            } catch (\Exception $e) {
212
                return json(['code'=>0, 'msg'=>$e->getMessage()]);
213
            }
214
            return json(['code'=>2, 'msg'=>'操作成功']);
215
        }
216
    }
217
218
    public function delete($id)
219
    {
220
        if ($this->request->isPost()) {
221
            if ($this->model->destroy($id)) {
222
                return json(['code'=>2]);
223
            } else {
224
                return json(['code'=>0]);
225
            }
226
        }
227
    }
228
229
    public function infoByOrderId($id)
230
    {
231
        $orderInfo = $this->detailsModel->find($id);
232
        $orderItemLists = $this->itemModel->where('order_id', $id)->select();
233
        $commission = new CommissionModel();
234
        $commission->order_id = $orderInfo->id;
235
        $commission->no = $orderInfo->no;
236
        $commission->contract_no = $orderInfo->contract_no;
237
        $commission->company_id = $orderInfo->company_id;
238
        $commission->company_name = $orderInfo->company_name;
239
        $commission->seller_id = $orderInfo->seller_id;
240
        $commission->seller_name = $orderInfo->seller_name;
241
        $commission->department_id = $orderInfo->department_id;
242
        $commission->department_name = $orderInfo->department_name;
243
244
        // var_dump($orderInfo);
245
        // var_dump($orderItemLists->toArray());
246
        // exit;
247
        foreach ($orderItemLists as  $orderItem) {
248
            $order = $this->doCommission($orderItem);
249
250
            $commission->general_money += $order['general_money'];
251
            $commission->special_money += $order['special_mone'];
252
        }
253
        $commission->general_money = number_money($commission->general_money);
254
        $commission->special_money = number_money($commission->special_money);
255
256
        return json(['code'=>2, 'data' => $commission]);
257
    }
258
259
    public function doCommission($orderItem=null)
260
    {
261
        $general_money = 0;
262
        $special_money = 0;
263
        
264
        switch ($orderItem->type) {
265
            case 1:
266
                $price_rate = intval(bcdiv($orderItem->actual_price, $orderItem->goods_price, 3)*1000);
267
                if ($price_rate < 1050) {
268
                    $ratio = $this->special_a;
269
                } elseif ($price_rate < 1100) {
270
                    $ratio = $this->special_b;
271
                } else {
272
                    $ratio = $this->special_c;
273
                }
274
                $general_money = 0;
275
                $special_money = intval(bcdiv(($orderItem->actual_money - $orderItem->fare - $orderItem->agency) * $ratio,1000));  
276
                break;
277
            case 2:
278
                $price_rate = intval(bcdiv($orderItem->actual_price, $orderItem->goods_price, 3)*1000);
279
                $ratio = intval(bcdiv($price_rate - 1000, 100) * 10 +10);
280
                $general_money = 0;
281
                $special_money = intval(bcdiv(($orderItem->actual_money - $orderItem->fare - $orderItem->agency) * $ratio,1000));  
282
                break;
283
            default:
284
                $price_rate = 0;
285
                $ratio = $this->general_ratio;
286
287
                $base_money = $orderItem->actual_amount * $orderItem->goods_price;
288
              
289
                $general_money = intval(bcdiv(($orderItem->actual_money - $base_money - $orderItem->fare - $orderItem->agency) * $ratio, 1000));
290
                $special_money = 0;
291
                break;
292
        }
293
        return [
294
            'general_money' => $general_money,
295
            'special_mone' => $special_money
296
        ];
297
    }
298
}

+ 2 - 1
app/controller/Department.php

@ -35,7 +35,7 @@ class Department extends Base
35 35
    {
36 36
        if ($this->request->isPost()) {
37 37
            $param = $this->request->param();
38
            
38
39 39
            try {
40 40
                if ($param['id']) {
41 41
                    $department = $this->model->find(intval($param['id']));
@ -44,6 +44,7 @@ class Department extends Base
44 44
                    $department->create_time = time();
45 45
                }
46 46
                $department->name = $param['name'];
47
                $department->director = $param['director'];
47 48
                
48 49
                $department->save();
49 50
            } catch (\Exception $e) {

+ 20 - 8
app/controller/Goods.php

@ -45,6 +45,16 @@ class Goods extends Base
45 45
        ]);
46 46
    }
47 47
48
    public function info($id)
49
    {
50
        if ($this->request->isAjax())
51
        {
52
            $data = $this->model->find($id); 
53
            
54
            return json(['code'=>2, 'data'=>$data]);
55
        }
56
    }
57
48 58
    public function save()
49 59
    {
50 60
        $categoryModel = new CategoryModel();
@ -54,17 +64,18 @@ class Goods extends Base
54 64
            
55 65
            try {
56 66
                if ($param['id']) {
57
                    $seller = $this->model->find(intval($param['id']));
67
                    $goods = $this->model->find(intval($param['id']));
58 68
                } else {
59
                    $seller = new GoodsModel();
60
                    $seller->create_time = time();
69
                    $goods = new GoodsModel();
70
                    $goods->create_time = time();
61 71
                }
62
                $seller->name = $param['name'];
63
                $seller->price = intval(bcmul($param['price'], 100));
64
                $seller->category_id = $param['category_id'];
65
                $seller->category_name = $categories[$param['category_id']];
72
                $goods->name = $param['name'];
73
                $goods->price = intval(bcmul($param['price'], 100));
74
                $goods->category_id = intval($param['category_id']);
75
                $goods->category_name = $categories[$param['category_id']];
76
                $goods->type = intval($param['type']);
66 77
                
67
                $seller->save();
78
                $goods->save();
68 79
            } catch (\Exception $e) {
69 80
                $this->error($e->getMessage());
70 81
            }
@ -81,6 +92,7 @@ class Goods extends Base
81 92
                    'name' => '',
82 93
                    'price' => 0.00,
83 94
                    'category_id' => 1,
95
                    'type' => 0,
84 96
                ];
85 97
            }
86 98

+ 65 - 30
app/controller/Order.php

@ -8,6 +8,8 @@ use app\model\OrderItem as OrderItemModel;
8 8
use app\model\OrderDetails as OrderDetailsModel;
9 9
use app\model\Department as DepartmentModel;
10 10
use think\facade\Db;
11
use app\model\Company as CompanyModel;
12
use app\model\Seller as SellerModel;
11 13
12 14
class Order extends Base
13 15
{
@ -49,23 +51,21 @@ class Order extends Base
49 51
            'query' => $this->request->param()
50 52
        ]);
51 53
        // 统计去除已取消合同
52
        // $map[] = ['status', '=', 0];
53
        // $total_contract_money = $this->detailsModel->where($map)->sum('contract_money');
54
        // $total_payment = $this->detailsModel->where($map)->sum('payment');
54
        $map[] = ['status', '=', 0];
55
        $total_contract_money = $this->detailsModel->where($map)->sum('contract_money');
56
        $total_payment = $this->detailsModel->where($map)->sum('payment');
55 57
56 58
        $page = $list->render();
57 59
58
        // return View::fetch();
59
60 60
        return View::fetch('',[
61
            // 'year' => $year,
61
            'year' => $year,
62 62
            'list' => $list,
63 63
            'page' => $page,
64
            // 'key' => $key,
65
            // 'month' => $month,
66
            // 'limit' => $limit,
67
            // 'total_contract_money' => round($total_contract_money, 2),
68
            // 'total_payment' => round($total_payment, 2)
64
            'key' => $key,
65
            'month' => $month,
66
            'limit' => $limit,
67
            'total_contract_money' => round($total_contract_money, 2),
68
            'total_payment' => round($total_payment, 2)
69 69
        ]);
70 70
    }
71 71
@ -76,7 +76,6 @@ class Order extends Base
76 76
77 77
    public function save($year=0)
78 78
    {
79
80 79
        if ($this->request->isPost()) {
81 80
            $param = $this->request->param();
82 81
            // var_dump($param);
@ -84,59 +83,95 @@ class Order extends Base
84 83
            try {
85 84
                if ($param['id']) {
86 85
                    $order = $this->model->find(intval($param['id']));
86
                    if (!$order){
87
                        throw new \think\exception\HttpException(404, '页面参数不正确');
88
                    } 
87 89
                } else {
88 90
                    $order = new OrderModel();
89 91
                    $order->create_time = time();
90 92
                }
93
91 94
                $order->no = $param['no'];
92 95
                $order->contract_no = $param['contract_no'];
93 96
                $order->contract_time = $param['contract_time'];
94
                $order->company_name = $param['company_name'];
95
                $order->department_name = $param['department_name'];
96
                $order->seller_name = $param['seller_name'];
97
                $order->company_id = $param['company_id'];
98
                $order->seller_id = $param['seller_id'];
97 99
                $order->consignor = $param['consignor'];
98
                $order->fare = $param['fare'];
99
                $order->agency = $param['agency'];
100
                $order->fare = int_money($param['fare']);
101
                $order->agency = int_money($param['agency']);
100 102
                $order->remark = $param['remark'];
101
                
103
                $order->payment = int_money($param['payment']);
104
                $order->pay_type = $param['pay_type'];
105
                $order->pay_time = $param['pay_time']? :'0000-00-00';
106
102 107
                $order->save();
103 108
            } catch (\Exception $e) {
104 109
                $this->error($e->getMessage());
105 110
            }
106 111
107
            $this->success('操作成功', 'seller/index');
112
            $this->success('操作成功', '/order/lists/'.$year);
108 113
        } else {
109 114
            $id = $this->request->has('id','route') ? intval($this->request->param('id')) : 0;
110 115
            if ($id) {
111 116
                $data = $this->model->find($id);
112 117
            } else {
113 118
                $data = [
114
                    'id' => '0',
119
                    'id' => 0,
115 120
                    'no' => '',
116 121
                    'contract_no' => '',
117 122
                    'contract_time' => '',
118
                    'company_name' => '',
119
                    'department_name' => '',
120
                    'seller_name' => '',
123
                    'company_id' => 0,
124
                    'seller_id' => 0,
121 125
                    'consignor' => '',
122
                    'fare' => '0.00',
123
                    'agency' => '0.00',
126
                    'fare' => 0,
127
                    'agency' => 0,
128
                    'pay_type'=> '',
129
                    'payment'=> 0,
130
                    'pay_time'=> '',
124 131
                    'remark' => '',
125 132
                ];
126 133
            }
134
            $sellers = SellerModel::column('name', 'id');
135
            $companies = CompanyModel::column('name', 'id');
127 136
            return View::fetch('',[
128 137
                'data' => $data,
129
                'year' => $year
138
                'year' => $year,
139
                'sellers' => $sellers,
140
                'companies' => $companies
130 141
            ]);
131 142
        }
132 143
    }
133 144
134 145
    public function delete($id)
135 146
    {
136
        if ($this->model->destroy($id)) {
137
            return json(['code'=>2]);
138
        } else {
139
            return json(['code'=>0]);
147
        if ($this->request->isPost()) {
148
            if ($this->model->destroy($id)) {
149
                return json(['code'=>2]);
150
            } else {
151
                return json(['code'=>0]);
152
            }
153
        }
154
    }
155
156
    public function cancel($id)
157
    {
158
        if ($this->request->isPost()) {
159
            if (OrderModel::update(['status' => -1, 'id' => $id])) {
160
                return json(['code'=>2]);
161
            } else {
162
                return json(['code'=>0]);
163
            }
164
        }
165
    }
166
167
    public function restore($id)
168
    {
169
        if ($this->request->isPost()) {
170
            if (OrderModel::update(['status' => 0, 'id' => $id])) {
171
                return json(['code'=>2]);
172
            } else {
173
                return json(['code'=>0]);
174
            }
140 175
        }
141 176
    }
142 177
}

+ 19 - 14
app/controller/OrderItem.php

@ -6,41 +6,41 @@ use think\facade\View;
6 6
use app\model\Order as OrderModel;
7 7
use app\model\OrderItem as OrderItemModel;
8 8
use app\model\OrderDetails as OrderDetailsModel;
9
use app\model\Department as DepartmentModel;
10
use think\facade\Db;
9
use app\model\facade\Goods;
11 10
12 11
class OrderItem extends Base
13 12
{
14 13
    protected $model;
15
    protected $orderModel;
16 14
    protected $detailsModel;
17 15
18 16
    public function __construct(App $app)
19 17
    {
20 18
        parent::__construct($app);
21 19
        $this->model = new OrderItemModel();
22
        $this->orderModel = new OrderModel();
23 20
        $this->detailsModel = new OrderDetailsModel();
24 21
    }
25 22
26 23
    public function index($order_id)
27 24
    {
28 25
        $list = $this->model->where('order_id', $order_id)->select();
29
        $orderInfo = $this->detailsModel->field('id,no,contract_no,company_name,contract_time')->find($order_id);
26
        $orderInfo = $this->detailsModel->find($order_id);
30 27
        $year = date('Y', strtotime($orderInfo->contract_time));
31 28
29
        $goodsSubtotalList = Goods::getGoodsSubtotal();
30
32 31
        return View::fetch('',[
33 32
            'list' => $list,
34 33
            'order_id' => $order_id,
35 34
            'orderInfo' => $orderInfo,
36 35
            'year' => $year,
36
            'goodsSubtotalList' => $goodsSubtotalList
37 37
        ]);
38 38
    }
39
40 39
    
41 40
    public function info($id)
42 41
    {
43 42
        $data = $this->model->find($id);
43
44 44
        if ($this->request->isAjax()) {
45 45
            return json(['code'=>2, 'data'=>$data]);
46 46
        }
@ -59,15 +59,20 @@ class OrderItem extends Base
59 59
                    $order = new OrderItemModel();
60 60
                }
61 61
                $order->order_id = intval($param['order_id']);
62
                $order->goods_category = $param['goods_category'];
62
                $order->goods_id = intval($param['goods_id']);
63
                $order->goods_price = intval(bcmul($param['goods_price'], 100));
63 64
                $order->goods_name = $param['goods_name'];
64
                $order->goods_price = $param['goods_price'];
65
                $order->sales_amount = $param['sales_amount'];
66
                $order->sales_price = $param['sales_price'];
67
                $order->actual_amount = $param['actual_amount'];
68
                $order->actual_price = $param['actual_price'];
69
                $order->agency = $param['agency'];
70
                $order->fare = $param['fare'];
65
                $order->goods_category_id = intval($param['goods_category_id']);
66
                $order->goods_category_name = $param['goods_category_name'];
67
                $order->sales_amount = strval($param['sales_amount']);
68
                $order->sales_price = intval(bcmul($param['sales_price'], 100));
69
                $order->sales_money = intval(bcmul($order->sales_amount , $order->sales_price));
70
                $order->actual_amount = strval($param['actual_amount']);
71
                $order->actual_price = intval(bcmul($param['actual_price'], 100));
72
                $order->actual_money = intval(bcmul($order->actual_amount, $order->actual_price));
73
                $order->agency = intval(bcmul($param['agency'], 100));
74
                $order->fare = intval(bcmul($param['fare'], 100));
75
                $order->other_fee = intval(bcmul($param['other_fee'], 100));
71 76
                $order->type = intval($param['type']);
72 77
                $order->remark = $param['remark'];
73 78
                

+ 25 - 0
app/model/Commission.php

@ -0,0 +1,25 @@
1
<?php
2
namespace app\model;
3
4
class commission extends \think\Model
5
{
6
    protected $schema = [
7
        'id' => 'int',
8
        'order_id' => 'int',
9
        'no' => 'string',
10
        'year' => 'int',
11
        'month' => 'int',
12
        'contract_no' => 'string',
13
        'time'=> 'date',
14
        'general_money' => 'int',
15
        'special_money' => 'int',
16
        'company_id' => 'int',
17
        'company_name' => 'string',
18
        'seller_id' => 'int',
19
        'seller_name' => 'string',
20
        'department_id' => 'int',
21
        'department_name' => 'string',
22
        'remark' => 'string',
23
        'create_time' => 'int'
24
    ];
25
}

+ 1 - 0
app/model/Department.php

@ -6,6 +6,7 @@ class Department extends \think\Model
6 6
    protected $schema = [
7 7
        'id' => 'int',
8 8
        'name' => 'string',
9
        'director' => 'steing',
9 10
        'create_time' => 'int'
10 11
    ];
11 12
}

+ 19 - 1
app/model/Goods.php

@ -1,7 +1,7 @@
1 1
<?php
2 2
namespace app\model;
3
use app\model\GoodsCategory;
4 3
use think\model\concern\SoftDelete;
4
use app\model\facade\GoodsCategory;
5 5
6 6
class Goods extends \think\Model
7 7
{
@ -11,6 +11,7 @@ class Goods extends \think\Model
11 11
        'category_name' => 'string',
12 12
        'name' => 'string',
13 13
        'price' => 'int',   // 单位分
14
        'type' => 'int',  // 提成类别
14 15
        'create_time' => 'int',
15 16
        'is_del' => 'int'
16 17
    ];
@ -18,4 +19,21 @@ class Goods extends \think\Model
18 19
    use SoftDelete;
19 20
    protected $deleteTime = 'is_del';
20 21
    protected $defaultSoftDelete = 0;
22
23
    public function getGoodsSubtotal()
24
    {
25
        $list = $this->order('id')->field('id,category_id,category_name,name,price')->select();
26
        $goodsCategories = GoodsCategory::getGoodsCategories();
27
        $data = [];
28
        foreach ($goodsCategories as $key => $val) {
29
            $data[$key] = ['goods_category_name'=>$val, 'items'=>[]];
30
            foreach ($list as $value) {
31
                // var_dump($value->category_id);
32
                if ($key==$value->category_id) {
33
                    array_push($data[$key]['items'], $value);
34
                }
35
            }
36
        }
37
        return $data;
38
    }
21 39
}

+ 5 - 0
app/model/GoodsCategory.php

@ -8,4 +8,9 @@ class GoodsCategory extends \think\Model
8 8
        'name' => 'string',
9 9
        'create_time' => 'int'
10 10
    ];
11
12
    public function getGoodsCategories()
13
    {
14
        return $this->order('id')->column('name', 'id');
15
    }
11 16
}

+ 17 - 3
app/model/Order.php

@ -3,7 +3,21 @@ namespace app\model;
3 3
4 4
class Order extends \think\Model
5 5
{
6
6
    protected $schema = [
7
        'id' => 'int',
8
        'no' => 'string',
9
        'contract_no' => 'string',
10
        'contract_time' => 'date',
11
        'company_id' => 'int',
12
        'seller_id' => 'int',
13
        'consignor' => 'string',
14
        'fare' => 'int',
15
        'agency' => 'int',
16
        'pay_type'=> "string",
17
        'payment'=> 'int',
18
        'pay_time'=> 'date',
19
        'remark' => 'string',
20
        'status' => 'int',
21
        'create_time' => 'int'
22
    ];
7 23
}
8
9
// select `o`.`id` AS `id`,`o`.`no` AS `no`,`o`.`contract_no` AS `contract_no`,(select sum((`oi`.`sales_amount` * `oi`.`sales_price`)) from `sale_order_item` `oi` where (`oi`.`order_id` = `o`.`id`)) AS `contract_money`,`o`.`contract_time` AS `contract_time`,`o`.`commany_id` AS `commany_id`,`o`.`company_name` AS `company_name`,`o`.`department_id` AS `department_id`,`o`.`department_name` AS `department_name`,`o`.`seller_id` AS `seller_id`,`o`.`seller_name` AS `seller_name`,`o`.`consignor` AS `consignor`,`o`.`fare` AS `fare`,`o`.`urgently` AS `urgently`,`o`.`waybill` AS `waybill`,`o`.`pay_type` AS `pay_type`,`o`.`pay_time` AS `pay_time`,`o`.`payment` AS `payment`,`o`.`uncollected` AS `uncollected`,`o`.`other_payment_date` AS `other_payment_date`,`o`.`other_payment_money` AS `other_payment_money`,`o`.`is_tax` AS `is_tax`,`o`.`tax_time` AS `tax_time`,`o`.`tax_money` AS `tax_money`,`o`.`other__tax_date` AS `other__tax_date`,`o`.`other_money` AS `other_money`,`o`.`tax_no` AS `tax_no`,`o`.`remark` AS `remark`,`o`.`is_commission` AS `is_commission`,`o`.`create_time` AS `create_time`,`o`.`agency` AS `agency`,month(`o`.`contract_time`) AS `month`,year(`o`.`contract_time`) AS `year`,`o`.`status` AS `status` from `sale_order` `o`

+ 25 - 0
app/model/OrderDetails.php

@ -3,4 +3,29 @@ namespace app\model;
3 3
4 4
class OrderDetails extends \think\Model
5 5
{
6
    protected $schema = [
7
        'id' => 'int',
8
        'no' => 'string',
9
        'contract_no' => 'string',
10
        'contract_time' => 'date',
11
        'contract_money' => 'double',
12
        'month' => 'int',
13
        'year' => 'int',
14
        'company_id' => 'int',
15
        'company_name' => 'string',
16
        'seller_id' => 'int',
17
        'seller_name' => 'string',
18
        'department_id' => 'int',
19
        'department_name' => 'string',
20
        'consignor' => 'string',
21
        'fare' => 'int',
22
        'agency' => 'int',
23
        'pay_type'=> "string",
24
        'payment'=> 'int',
25
        'pay_time'=> 'date',
26
        'remark' => 'string',
27
        'is_commission' => 'int',
28
        'status' => 'int',
29
        'create_time' => 'int'
30
    ];
6 31
}

+ 3 - 2
app/model/OrderItem.php

@ -11,16 +11,17 @@ class OrderItem extends \think\Model
11 11
        'goods_id' => 'int',
12 12
        'goods_name' => 'string',
13 13
        'goods_price' => 'int',
14
        'sales_amount' => 'string',
14
        'sales_amount' => 'decimal',
15 15
        'sales_price' => 'int',   // 单位分
16 16
        'sales_money' => 'int',   // 单位分
17
        'actual_amount' => 'string',
17
        'actual_amount' => 'decimal',
18 18
        'actual_price' => 'int',   // 单位分
19 19
        'actual_money' => 'int',   // 单位分
20 20
        'status' => 'int',
21 21
        'remark' => 'string',
22 22
        'fare' => 'int',  // 单位分
23 23
        'agency' => 'int',  // 单位分
24
        'other_fee' => 'int',  // 单位分
24 25
        'type' => 'int',
25 26
        'create_time' => 'int'
26 27
    ];

+ 12 - 0
app/model/facade/Goods.php

@ -0,0 +1,12 @@
1
<?php
2
namespace app\model\facade;
3
4
use think\Facade;
5
6
class Goods extends Facade
7
{
8
    protected static function getFacadeClass()
9
    {
10
    	return 'app\model\Goods';
11
    }
12
}

+ 12 - 0
app/model/facade/GoodsCategory.php

@ -0,0 +1,12 @@
1
<?php
2
namespace app\model\facade;
3
4
use think\Facade;
5
6
class GoodsCategory extends Facade
7
{
8
    protected static function getFacadeClass()
9
    {
10
    	return 'app\model\GoodsCategory';
11
    }
12
}

+ 4 - 0
public/test.php

@ -0,0 +1,4 @@
1
<?php
2
echo PHP_INT_MAX;
3
echo "\n";
4
echo 900000000 * 90000;

+ 7 - 3
route/app.php

@ -15,7 +15,7 @@ Route::pattern([
15 15
    'key' => '\w+',
16 16
    'id'   => '\d+',
17 17
    'year'   => '\d+',
18
    'order_id'   => '\d+',
18
    'month' => '\d+',
19 19
]);
20 20
21 21
Route::get('company/index/[:key]', 'company/index');
@ -29,8 +29,12 @@ Route::get('goods_category/index', 'goods_category/index');
29 29
Route::get('goods_category/info', 'goods_category/info');
30 30
Route::post('goods_category/save', 'goods_category/save');
31 31
Route::get('goods/index/[:cid]', 'goods/index')->pattern(['cid'=>'\d+']);
32
Route::get('goods/info/:id', 'goods/info');
32 33
Route::rule('goods/save/:id', 'goods/save');
33 34
Route::get('order/index', 'order/index');
34 35
Route::get('order/lists/:year', 'order/lists');
35
Route::rule('order/save/:id', 'order/save');
36
Route::get('order_item/index/:order_id', 'order_item/index')->pattern(['order_id'=>'\d+']);
36
Route::rule('order/save/:year/:id', 'order/save');
37
Route::get('order_item/:order_id', 'order_item/index')->pattern(['order_id'=>'\d+']);
38
Route::post('order_item/save/:id', 'order_item/save');
39
Route::get('commission/:year/:month', 'commission/index')->pattern(['order_id'=>'\d+']);
40
Route::get('commission/lists/:year/:month', 'commission/lists')->pattern(['order_id'=>'\d+']);

+ 117 - 0
view/commission/index.html

@ -0,0 +1,117 @@
1
{layout name="layout" /}
2
3
<nav class="breadcrumb">
4
    <span><a href="/">首页</a></span>
5
    <span>&gt;</span>
6
    <span><a href="/commission/year">提成汇总</a></span>
7
    <span>&gt;</span>
8
    <span>{$year} 年度</span>
9
    <span>{$month} 月份</span>
10
</nav>
11
12
<div class="content">
13
    <div class="row mt-10">
14
        <div class="col-md-3 ">
15
            <a href="/commission/year" class="btn btn-default radius">全部年度</a>
16
            <a href="/commission/lists/{$year}/{$month}" class="btn btn-primary radius">合同明细</a>
17
        </div>
18
        <div class="col-md-2">
19
        </div>
20
    </div>
21
    <!--startprint-->
22
    <div class="row" style="margin: 10px 0;">
23
        <div class="col-md-3 noprint">
24
            <label for="month" class="form-label col-md-8 text-right mt-5">
25
                请选择月份 :
26
            </label>
27
            <div class="formControls col-md-4" style="width: 100px;">
28
                <input type="hidden" name="year" id="year" value="{$year}">
29
                <select class="form-control input-sm col-md-2" name="month" id="month">
30
                    {for start="1" end="13"}
31
                    <option value="{$i}" {eq name="month" value="$i" }selected{/eq}>{$i}月</option>
32
                    {/for}
33
                </select>
34
            </div>
35
        </div>
36
        <div class="col-md-5 text_center">
37
            <h3>{$month} 月份提成汇总表</h3>
38
        </div>
39
        <div class="col-md-2 noprint" style="text-align:right;">
40
            <div class="btn-group ">
41
                <button type="button" class="btn btn-default" onclick=" doPrint()">打印</button>
42
            </div>
43
        </div>
44
    </div>
45
    <div class="row">
46
        <div class="col-md-10 col-md-offset-1">
47
            <table class=" table table-hover table-bordered">
48
                <thead>
49
                    <tr>
50
                        <th>序 号</th>
51
                        <th>销售员</th>
52
                        <th>总利润</th>
53
                        <th>提成比例</th>
54
                        <th>提成金额</th>
55
                        <th>特批提成</th>
56
                        <th>比例</th>
57
                        <th>提成金额</th>
58
                        <th>合 计</th>
59
                        <th>备 注</th>
60
                    </tr>
61
                </thead>
62
                <tbody>
63
                    {foreach $list as $key=>$value}
64
                    <tr class="text-center">
65
                        <td>{$key+1}</td>
66
                        <td>{$value.seller_name}</td>
67
                        <td>{$value.profit|format_money}</td>
68
                        <td>{$value.general_ratio}</td>
69
                        <td>{$value.general_money|format_money}</td>
70
                        <td>{$value.total_special_money|format_money}</td>
71
                        <td>{$value.special_ratio}</td>
72
                        <td>{$value.special_money|format_money}</td>
73
                        <td>{$value.general_money + $value.special_money|format_money}</td>
74
                        <td>{$value.remark}</td>
75
                    </tr>
76
                    {/foreach}
77
78
                    <tr>
79
                        <td colspan='2' style="text-align: center;font-weight:bold;">合计</td>
80
                        <td></td>
81
                        <td></td>
82
                        <td>25%</td>
83
                        <td></td>
84
                        <td></td>
85
                        <td>100%</td>
86
                        <td></td>
87
                        <td></td>
88
                    </tr>
89
                </tbody>
90
            </table>
91
        </div>
92
    </div>
93
    <div class="row text-center col-md-offset-2">
94
        <span class="col-md-2" style="line-height: 40px;margin-right:50px;">制表:</span>
95
        <span class="col-md-2" style="line-height: 40px;margin-right:50px;">复核:</span>
96
        <span class="col-md-2" style="line-height: 40px;margin-right:50px;">审批:</span>
97
        <span class="col-md-2" style="line-height: 40px;margin-right:50px;">总经理签字:</span>
98
    </div>
99
    <div class="row text-center col-md-offset-2">
100
        <span class="col-md-2" style="line-height: 40px;margin-right:50px;">日期:</span>
101
        <span class="col-md-2" style="line-height: 40px;margin-right:50px;">日期:</span>
102
        <span class="col-md-2" style="line-height: 40px;margin-right:50px;">日期:</span>
103
        <span class="col-md-2" style="line-height: 40px;margin-right:50px;">日期:</span>
104
    </div>
105
    <!--endprint-->
106
</div>
107
108
<script>
109
    $("#month").change(function () {
110
        var year = $("#year").val();
111
        var month = $("#month").val();
112
        window.location.href = "/commission/"+year+"/"+month;
113
    })
114
</script>
115
</body>
116
117
</html>

+ 101 - 0
view/commission/lists.html

@ -0,0 +1,101 @@
1
{layout name="layout" /}
2
3
<nav class="breadcrumb">
4
    <span><a href="/">首页</a></span>
5
    <span>&gt;</span>
6
    <span><a href="/commission/{$year}/{$month}">提成汇总</a></span>
7
    <span>&gt;</span>
8
    <span>{$year} 年度</span>
9
    <span>{$month} 月份</span>
10
</nav>
11
12
<div class="content">
13
    <div class="row  mt-10">
14
        <div class="col-md-2 col-xs-3 text-center">
15
            <!-- <a href="/commission/save/{$year}/0" class="btn btn-success radius">新增</a> -->
16
            <a href="javascript:window.history.back();" class="btn btn-default radius">返回</a>
17
        </div>
18
        <div class="col-md-6">
19
                <div class="col-md-4">
20
                    <input type="text" class="form-control" name="key" id="key" value="{$key}"
21
                        placeholder="请输入公司名称">
22
                </div>
23
                <div class="col-md-3" style="text-align:left;">
24
                    <div class="btn-group ">
25
                        <button type="submit" class="btn btn-success">搜索</button>
26
                    </div>
27
                    <div class="btn-group ">
28
                        <a href="/order/lists/{$year}" class="btn btn-danger ml-10">清除</a>
29
                    </div>
30
                </div>
31
            </form>
32
        </div>
33
    </div>
34
    <div class="col-md-10 mt-10">
35
        <table class="table table-hover table-bordered table-condensed">
36
            <thead>
37
                <tr>
38
                    <th>序号</th>
39
                    <th>公司名称</th>
40
                    <th>合同号</th>
41
                    <th>计提日期</th>
42
                    <th>一般提成</th>
43
                    <th>特别提成</th>
44
                    <th>销售员</th>
45
                    <th>备注</th>
46
                    <th style="width: 180px;">操作</th>
47
                </tr>
48
            </thead>
49
            <tbody>
50
                {foreach $list as $val}
51
                <tr>
52
                    <td>{$val.no}</td>
53
                    <td>{$val.company_name}</td>
54
                    <td>{$val.contract_no}</td>
55
                    <td>{$val.time}</td>
56
                    <td>{$val.general_money|format_money}</td>
57
                    <td>{$val.special_money|format_money}</td>
58
                    <td>{$val.seller_name}</td>
59
                    <td>{$val.remark}</td>
60
                    <td class="td-manager">
61
                        <a href="/order_item/{$val.order_id}">合同明细</a>
62
                        <a href="/commission/save/{$val.id}">修改</a>
63
                        <a href="javascript:void(0);" onclick="del('{$val.id}', this)">删除</a>
64
                    </td>
65
                </tr>
66
                {/foreach}
67
                <tr>
68
                    <td>合计</td>
69
                    <td class="text-left" colspan="3">{$list|count}</td>
70
                    <td>{$total_special_money}</td>
71
                    <td>{$total_special_money}</td>
72
                    <td></td>
73
                    <td></td>
74
                    <td></td>
75
                </tr>
76
            </tbody>
77
        </table>
78
    </div>
79
</div>
80
81
<script>
82
    function del(id, obj) {
83
        $.ajax({
84
            url: "/commission/delete",
85
            type: "POST",
86
            data: {
87
                "id": id
88
            },
89
            dataType: 'json',
90
            success: function (data) {
91
                // console.log(data.code);
92
                if (data.code == 0) {
93
                    $(obj).parents("tr").remove();
94
                } else {
95
                    alert(data.msg);
96
                }
97
                return false;
98
            }
99
        });
100
    }
101
</script>

+ 26 - 0
view/commission/year.html

@ -0,0 +1,26 @@
1
{layout name="layout" /}
2
3
<nav class="breadcrumb">
4
    <span><a href="/">首页</a></span>
5
    <span>&gt;</span>
6
    <span>销售提成</span>
7
</nav>
8
9
<div class="content">
10
    <div class="box-year">
11
        {for start="$init_year" end="$current_year" comparison="elt" step="1" name="year" }
12
        <div class="col-md-3">
13
            <a href="/commission/{$year}/1">
14
                <h3>{$year}年度</h3>
15
                <div>
16
                    <img src="/static/images/nianbao1.png" alt="{$year}年度" title="{$year}年度">
17
                </div>
18
            </a>
19
        </div>
20
        {/for}
21
    </div>
22
</div>
23
24
<script>
25
   
26
</script>

+ 15 - 0
view/department/index.html

@ -25,6 +25,7 @@
25 25
                    </th>
26 26
                    <th class="text-center">id</th>
27 27
                    <th class="text-center">部门名称</th>
28
                    <th class="text-center">主管</th>
28 29
                    <th class="text-center">操作</th>
29 30
                </tr>
30 31
            </thead>
@ -36,6 +37,7 @@
36 37
                    </td>
37 38
                    <td class="text-center">{$value.id}</td>
38 39
                    <td class="text-center">{$value.name}</td>
40
                    <td class="text-center">{$value.director}</td>
39 41
                    <td class="text-center td-manager">
40 42
                        <a href="javascript:void(0);" onClick="save('{$value.id}')">修改</a>
41 43
                        <a href="javascript:void(0);" onClick="del('{$value.id}', this)" class="ml-10">删除</a>
@ -69,6 +71,18 @@
69 71
                        </div>
70 72
                    </div>
71 73
                </div>
74
                <div class="row">
75
                    <div class="col-md-4">
76
                        <div class="form-group">
77
                            <label for="director">主管</label>
78
                        </div>
79
                    </div>
80
                    <div class="col-md-4">
81
                        <div class="form-group">
82
                            <input type="text" class="form-control" name="director" id="director" placeholder="主管">
83
                        </div>
84
                    </div>
85
                </div>
72 86
            </form>
73 87
        </div>
74 88
        <div class="modal-footer">
@ -93,6 +107,7 @@
93 107
                    var data = res.data;
94 108
                    $("#id").val(data.id);
95 109
                    $("#name").val(data.name);
110
                    $("#director").val(data.director);
96 111
                }
97 112
            }, 'json');
98 113
        } else {

+ 5 - 2
view/goods/index.html

@ -39,7 +39,7 @@
39 39
        <table class=" table table-hover table-bordered">
40 40
            <thead>
41 41
                <tr class="text-center bg-info">
42
                    <td class="text-left" colspan="4">
42
                    <td class="text-left" colspan="5">
43 43
                        {empty name="category_name"}
44 44
                        全部产品: {$list->total()}
45 45
                        {else /}
@ -63,10 +63,12 @@
63 63
                    <th class="text-center">类别</th>
64 64
                    <th class="text-center">名称</th>
65 65
                    <th class="text-center">价格</th>
66
                    <th class="text-center">提成类型</th>
66 67
                    <th class="text-center">操作</th>
67 68
                </tr>
68 69
            </thead>
69 70
            <tbody>
71
                {php}$types=['一般', '特批1', '特批2'];{/php}
70 72
                {foreach $list as $value}
71 73
                <tr>
72 74
                    <td>
@ -75,7 +77,8 @@
75 77
                    <td class="text-center">{$value.id}</td>
76 78
                    <td class="text-center"><a href="/goods/index/{$value['category_id']}">{$value.category_name}</a></td>
77 79
                    <td class="text-center">{$value.name}</td>
78
                    <td class="text-center">{:number_format(bcdiv($value['price'],100,2),2)}</td>
80
                    <td class="text-center">{$value['price']|format_money}</td>
81
                    <td class="text-center">{$types[$value['type']]}</td>
79 82
                    <td class="text-center td-manager">
80 83
                        <a href="/goods/save/{$value['id']}">修改</a>
81 84
                        <a href="javascript:void(0);" class="ml-10" onClick="del('{$value.id}', this)">删除</a>

+ 22 - 6
view/goods/save.html

@ -15,6 +15,22 @@
15 15
    </div>
16 16
    <form role="form" id="form-seller" action="" method="POST">
17 17
        <input type="hidden" name="id" id="id" value="{$data.id}">
18
        <div class="row">
19
            <div class="col-md-2">
20
                <div class="form-group" style="text-align:right;line-height:40px;">
21
                    <label form-label for="category_id">产品类别:</label>
22
                </div>
23
            </div>
24
            <div class="col-md-4">
25
                <div class="form-group">
26
                    <select name="category_id" id="category_id" class="form-control">
27
                        {foreach $categories as $key=>$val}
28
                        <option value="{$key}" {eq name="data.category_id" value="$key"}selected{/eq}>{$val}</option>
29
                        {/foreach}
30
                    </select>
31
                </div>
32
            </div>
33
        </div>
18 34
        <div class="row">
19 35
            <div class="col-md-2">
20 36
                <div class="form-group" style="text-align:right;line-height:40px;">
@ -36,7 +52,7 @@
36 52
            </div>
37 53
            <div class="col-md-4">
38 54
                <div class="form-group">
39
                    <input type="number" class="form-control" name="price" id="price" value="{:number_format(bcdiv($data['price'],100,2),2)}" placeholder="价格">
55
                    <input type="number" class="form-control" name="price" id="price" value="{$data['price']|number_money}" placeholder="价格">
40 56
                </div>
41 57
            </div>
42 58
            <span style='color:red;' id="error_msg"></span>
@ -44,15 +60,15 @@
44 60
        <div class="row">
45 61
            <div class="col-md-2">
46 62
                <div class="form-group" style="text-align:right;line-height:40px;">
47
                    <label form-label for="category_id">种类:</label>
63
                    <label form-label for="category_id">提成类型:</label>
48 64
                </div>
49 65
            </div>
50 66
            <div class="col-md-4">
51 67
                <div class="form-group">
52
                    <select name="category_id" id="category_id" class="form-control">
53
                        {foreach $categories as $key=>$val}
54
                        <option value="{$key}" {eq name="data.category_id" value="$key"}selected{/eq}>{$val}</option>
55
                        {/foreach}
68
                    <select name="type" id="type" class="form-control">
69
                        <option value="0" {eq name="data.type" value="0"}selected{/eq}>一般</option>
70
                        <option value="1" {eq name="data.type" value="1"}selected{/eq}>特批1</option>
71
                        <option value="2" {eq name="data.type" value="2"}selected{/eq}>特批2</option>
56 72
                    </select>
57 73
                </div>
58 74
            </div>

+ 0 - 131
view/order/index2.html

@ -1,131 +0,0 @@
1
{layout name="layout" /}
2
3
<nav class="breadcrumb">
4
    <span><a href="/">首页</a></span>
5
    <span>&gt;</span>
6
    <span><a href="javascript:void(0);">销售明细</a></span>
7
</nav>
8
<div class="content">
9
    <div class="row" style="margin: 0 0;">
10
        <div class="col-md-2 col-xs-3 btn-top-box text-center">
11
            <a href="/order/save/0" class="btn btn-success radius">新增</a>
12
        </div>
13
        <div class="col-md-6 btn-top-box">
14
            <form action="/order/index" method="get">
15
                <div class="col-md-1">
16
                </div>
17
                <div class="col-md-4">
18
                    <input type="text" class="form-control" name="key" id="key" value="{$key|default=''}"
19
                        placeholder="请输入公司名称">
20
                </div>
21
                <div class="col-md-3" style="text-align:left;">
22
                    <div class="btn-group ">
23
                        <button type="submit" class="btn btn-success">搜索</button>
24
                    </div>
25
                    <div class="btn-group ">
26
                        <a href="/order" class="btn btn-danger ml-10">清除</a>
27
                    </div>
28
                </div>
29
            </form>
30
        </div>
31
    </div>
32
    <div class="col-md-12" style="margin-top: 20px;">
33
        <table class=" table table-hover table-bordered">
34
            <thead>
35
                <tr>
36
                    <th width="25">
37
                        <input type="checkbox" value="" name="">
38
                    </th>
39
                    <!-- <th class="text-center">id</th> -->
40
                    <th class="text-center">序号</th>
41
                    <th class="text-center">购货单位</th>
42
                    <th class="text-center">余额初期值</th>
43
                    <th class="text-center">操作</th>
44
                </tr>
45
            </thead>
46
            <tbody>
47
                        {foreach $list as $value}
48
                <tr>
49
                    <td>
50
                        <input type="checkbox" value="{$value.id}" name="checkbox[]">
51
                    </td>
52
                    <td class="text-center">{$value.id}</td>
53
                    <td class="text-center">{$value['name']}</td>
54
                    <td class="text-center">{$value['initial_balance']}</td>
55
                    <td class="text-center">
56
                        <a href="/company/save/{$value['id']}">修改</a>
57
                        <a href="javascript:void(0);" class="ml-10" onClick="del({$value.id|intval}, this)">删除</a> 
58
                    </td>
59
                </tr>
60
                {/foreach}
61
            </tbody>
62
        </table>
63
    </div>
64
    <div class="pagelist">
65
        {$page|raw}
66
    </div>
67
</div>
68
69
<script>
70
    function del(id, obj) {
71
        $.post('/company/delete', {
72
            'id': id
73
        }, function (res) {
74
            if (res.code == 2) {
75
                $(obj).parents("tr").remove();
76
                alert('删除成功!');
77
            } else {
78
                alert('删除失败, 请稍后重试.');
79
                return false;
80
            }
81
        }, 'json');
82
    }
83
</script>
84
<?php
85
$type = ['一般', '特批1', '特批2'];
86
$tr_type = ['info', 'warning', 'danger'];
87
foreach ($data as $value) {
88
?>
89
    <tr class="<?php echo $tr_type[$value['type']]; ?>">
90
        <td><?php echo $value['id']; ?></td>
91
        <td><?php echo $value['company']; ?></td>
92
        <td><?php echo $value['contract_no']; ?></td>
93
        <td><?php echo $value['goods_category']; ?></td>
94
        <td><?php echo $value['goods_type']; ?></td>
95
        <td><?php echo $value['amount']; ?></td>
96
        <td><?php echo $value['price']; ?></td>
97
        <td><?php echo $value['base_price']; ?></td>
98
        <td><?php echo $value['type'] ? $value['price_rate'] : ''; ?></td>
99
        <td><?php echo $value['contract_value']; ?></td>
100
        <td><?php echo $value['agency']; ?></td>
101
        <td><?php echo $value['type'] ? '' : $value['base_value']; ?></td>
102
        <td><?php echo $value['type'] ? $value['actual_value'] : ''; ?></td>
103
        <td><?php echo $value['shipping']; ?></td>
104
        <td><?php echo $value['project']; ?></td>
105
        <td><?php echo $value['receive_money']; ?></td>
106
        <td><?php echo $value['period_balance']; ?></td>
107
        <td><?php echo $value['actual_money']; ?></td>
108
        <td><?php echo $value['current_balance']; ?></td>
109
        <td><?php echo $value['type'] ? '' : $value['total_profit']; ?></td>
110
        <td><?php echo $value['type'] ? $value['c_rate'] : ''; ?></td>
111
        <td><?php echo $value['type'] ? $value['c_money'] : ''; ?></td>
112
        <td><?php echo $value['seller']; ?></td>
113
        <td class="td-manager">
114
            <a href="javascript:void(0);" onclick="del(<?php echo $value['id']; ?>, this)">删除</a>
115
            <a href="javascript:void(0);" onclick="edit(<?php echo $value['id']; ?>)">修改</a></td>
116
    </tr>
117
<?php
118
}
119
?>
120
<th>发货人</th>
121
<th>发货运费</th>
122
<th>紧急发货</th>
123
<th>运单号</th>
124
<th>付款方式</th>
125
<th>到款时间</th>
126
<th>到款金额</th>
127
<th>运费</th>
128
<th>发票</th>
129
<th>开票日期</th>
130
<th>开票金额</th>
131
<th>发票号</th>

+ 262 - 28
view/order/lists.html

@ -5,17 +5,17 @@
5 5
    <span>&gt;</span>
6 6
    <span><a href="/order/index">销售订单</a></span>
7 7
    <span>&gt;</span>
8
    <span>{//$year!=0?$year:"全部"} 年度</span>
8
    <span>{$year!=0?$year:"全部"} 年度</span>
9 9
</nav>
10 10
11 11
<div class="content">
12 12
    <div class="row" style="margin: 10px 0;">
13 13
        <div class="col-md-2 col-xs-3 text-center">
14
            <a href="/order/save/{//$year}/0" class="btn btn-success radius">新增</a>
14
            <a href="/order/save/{$year}/0" class="btn btn-success radius">新增</a>
15 15
        </div>
16 16
        <div class="col-md-8">
17
            <form action="/order/lists/{//$year}" method="get">
18
                {//notempty name="year"}
17
            <form action="/order/lists/{$year}" method="get">
18
                {notempty name="year"}
19 19
                <label for="month" class="form-label col-md-2 text-right mt-5">
20 20
                    请选择月份 :
21 21
                </label>
@ -23,24 +23,23 @@
23 23
                    <select class="form-control input-sm" name="month" id="month">
24 24
                        {for start="0" end="13"}
25 25
                        {eq name="i" value="0"}
26
                        <option value="{$i}"{//eq name="month" value="0"}selected{///eq}>全年</option>
26
                        <option value="{$i}" {eq name="month" value="0" }selected{/eq}>全年</option>
27 27
                        {else/}
28
                        <option value="{$i}"{//eq name="month" value="$i"}selected{///eq}>{$i}月</option>
28
                        <option value="{$i}" {eq name="month" value="$i" }selected{/eq}>{$i}月</option>
29 29
                        {/eq}
30 30
                        {/for}
31 31
                    </select>
32 32
                </div>
33
                {///notempty}
33
                {/notempty}
34 34
                <div class="col-md-4">
35
                    <input type="text" class="form-control" name="key" id="key" value="{//$key}"
36
                        placeholder="请输入公司名称">
35
                    <input type="text" class="form-control" name="key" id="key" value="{$key}" placeholder="请输入公司名称">
37 36
                </div>
38 37
                <div class="col-md-3" style="text-align:left;">
39 38
                    <div class="btn-group ">
40 39
                        <button type="submit" class="btn btn-success">搜索</button>
41 40
                    </div>
42 41
                    <div class="btn-group ">
43
                        <a href="/order/lists/{//$year}" class="btn btn-danger ml-10">清除</a>
42
                        <a href="/order/lists/{$year}" class="btn btn-danger ml-10">清除</a>
44 43
                    </div>
45 44
                </div>
46 45
            </form>
@ -52,13 +51,13 @@
52 51
                <tr class="text-center bg-info">
53 52
                    <td>统计</td>
54 53
                    <td colspan="11" class="text-left">
55
                        总销售金额 : ¥{//$total_contract_money} | 总到款金额: ¥{//$total_payment}
54
                        总销售金额 : ¥{$total_contract_money} | 总到款金额: ¥{$total_payment}
56 55
                    </td>
57
                    <td colspan="2">
56
                    <td colspan="3">
58 57
                        <span>每页行数:</span>
59 58
                        <select name="limit" id="limit" onchange="changLimit()">
60 59
                            {for start="10" end="101" step="10"}
61
                            <option value="{$i}" {//eq name="limit" value="$i"}selected{///eq}>{$i}</option>
60
                            <option value="{$i}" {eq name="limit" value="$i" }selected{/eq}>{$i}</option>
62 61
                            {/for}
63 62
                        </select>
64 63
                    </td>
@ -75,30 +74,45 @@
75 74
                    <th>销售员</th>
76 75
                    <th>到款金额</th>
77 76
                    <th>未到款</th>
78
                    <th>末期余额</th>
79
                    <th>提成</th>
77
                    <!-- <th>末期余额</th> -->
78
                    <th style="min-width: 40px;">提成</th>
80 79
                    <th>操作</th>
81 80
                </tr>
82 81
            </thead>
83 82
            <tbody>
84 83
                {foreach $list as $value}
85
                <tr class="text-center">
84
                <tr class="text-center {eq name='value.status' value='-1'}bg-danger{/eq}">
86 85
                    <td>{$value.no}</td>
87 86
                    <td>{$value.month}</td>
88 87
                    <td class="text-left">{$value.company_name}</td>
89
                    <td class="text-left"><a href="/order/item/{$value.id}">{$value.contract_no}</a></td>
90
                    <td>{//$value.contract_money}</td>
88
                    <td class="text-left"><a href="/order_item/{$value.id}">{$value.contract_no}</a></td>
89
                    <td>{$value.contract_money|format_money}</td>
91 90
                    <td>{$value.contract_time}</td>
92
                    <td>{$value.fare}</td>
93
                    <td>{$value.agency}</td>
91
                    <td>{$value.fare|format_money}</td>
92
                    <td>{$value.agency|format_money}</td>
94 93
                    <td>{$value.seller_name}</td>
95
                    <td>{$value.payment}</td>
96
                    <td>{//$value.contract_money-$value.payment|round=2}</td>
97
                    <td>--</td>
98
                    <td>{$value.is_commission}</td>
94
                    <td>{$value.payment|format_money}</td>
95
                    <td>{$value.contract_money-$value.payment|format_money}</td>
96
                    <!-- <td>--</td> -->
97
                    <td class="td-status">
98
                        {eq name="value.is_commission" value="0"}
99
                        <a href="javascript:void(0);" title="计提" data-value='{$value.is_commission}'
100
                            onclick="commission('{$value.id}', this)"><span
101
                                class="label label-default radius">否</span></a>
102
                        {else/}
103
                        <a href="javascript:void(0);" title="取消" data-value='{$value.is_commission}'
104
                            onclick="commission('{$value.id}', this)"><span
105
                                class="label label-success radius">是</span></a>
106
                        {/eq}
107
                    </td>
99 108
                    <td class="td-manager">
100
                        <a href="/order_item/index/{$value.id}">产品明细</a>
101
                        <a href="/order/save/{$value.id}" onclick="edit()">修改</a>
109
                        <a href="/order_item/{$value.id}">明细</a>
110
                        <a href="/order/save/{$year}/{$value.id}" onclick="edit()">修改</a>
111
                        {eq name='value.status' value='-1'}
112
                        <a href="javascript:void(0);" data-value='-1' onclick="status('{$value.id}', this)">恢复</a>
113
                        {else/}
114
                        <a href="javascript:void(0);" data-value='0' onclick="status('{$value.id}', this)">取消</a>
115
                        {/eq}
102 116
                        <a href="javascript:void(0);" onclick="del('{$value.id}', this)">删除</a>
103 117
                    </td>
104 118
                </tr>
@ -111,6 +125,93 @@
111 125
    </div>
112 126
</div>
113 127
128
<div class="modal" tabindex="-1" role="dialog" data-backdrop="false" id="myModal" aria-labelledby="myModalLabel"
129
    style="right: 10%;">
130
    <div class="modal-dialog" role="document">
131
        <div class="modal-content">
132
            <div class="modal-header">
133
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
134
                        aria-hidden="true">&times;</span></button>
135
                <h4 class="modal-title">计提</h4>
136
            </div>
137
            <div class="modal-body">
138
                <form role="form" id="form-commission">
139
                    <input type="hidden" name="id" id="id" value="0">
140
                    <input type="hidden" name="order_id" id="order_id" value="">
141
                    <div class="row">
142
                        <div class="col-md-4">
143
                            <div class="form-group">
144
                                <label for="name">序号</label>
145
                                <input type="text" class="form-control" name="no" id="no" placeholder="序号">
146
                            </div>
147
                        </div>
148
                        <div class="col-md-4">
149
                            <div class="form-group">
150
                                <label for="name">合同号</label>
151
                                <input type="text" class="form-control" name="contract_no" id="contract_no"
152
                                    placeholder="合同号">
153
                            </div>
154
                        </div>
155
                        <div class="col-md-4">
156
                            <div class="form-group">
157
                                <label for="name">购货单位</label>
158
                                <input type="text" class="form-control" name="company_name" id="company_name"
159
                                    placeholder="公司名称">
160
                                <input type="hidden" name="company_id" id="company_id" value="">
161
                            </div>
162
                        </div>
163
                    </div>
164
                    <div class="row">
165
                        <div class="col-md-4">
166
                            <div class="form-group">
167
                                <label for="name">一般提成金额</label>
168
                                <input type="number" class="form-control" name="general_money" id="general_money"
169
                                    placeholder="一般提成金额">
170
                            </div>
171
                        </div>
172
                        <div class="col-md-4">
173
                            <div class="form-group">
174
                                <label for="name">特别提成金额</label>
175
                                <input type="number" class="form-control" name="special_money" id="special_money"
176
                                    placeholder="特别提成金额">
177
                            </div>
178
                        </div>
179
                        <div class="col-md-3">
180
                            <div class="form-group">
181
                                <label for="name">提成日期</label>
182
                                <input type="date" class="form-control" name="time" id="time" value=""
183
                                    placeholder="提成日期">
184
                            </div>
185
                        </div>
186
                    </div>
187
                    <div class="row">
188
                        <div class="col-md-4">
189
                            <div class="form-group">
190
                                <label for="name">销售员</label>
191
                                <input type="text" class="form-control" name="seller_name" id="seller_name"
192
                                    placeholder="销售员">
193
                                <input type="hidden" name="seller_id" id="seller_id" value="">
194
                                <input type="hidden" name="department_id" id="department_id" value="">
195
                                <input type="hidden" name="department_name" id="department_name" value="">
196
                            </div>
197
                        </div>
198
                        <div class="col-md-8">
199
                            <div class="form-group">
200
                                <label for="name">备注</label>
201
                                <textarea class="form-control" name="remark" id="remark" rows="3"></textarea>
202
                            </div>
203
                        </div>
204
                    </div>
205
                </form>
206
            </div>
207
            <div class="modal-footer">
208
                <button type="button" class="btn btn-default" onclick="closeModel()">Close</button>
209
                <button type="button" class="btn btn-success" onclick="doSave()">Save</button>
210
            </div>
211
        </div><!-- /.modal-content -->
212
    </div><!-- /.modal-dialog -->
213
</div><!-- /.modal -->
214
114 215
<script>
115 216
    function del(id, obj) {
116 217
        $.ajax({
@ -120,7 +221,7 @@
120 221
                "id": id
121 222
            },
122 223
            dataType: 'json',
123
            success: function(data) {
224
            success: function (data) {
124 225
                if (data.code == 2) {
125 226
                    $(obj).parents("tr").remove();
126 227
                } else {
@ -130,4 +231,137 @@
130 231
            }
131 232
        });
132 233
    }
133
</script>
234
235
    function status(id, obj) {
236
        var status = $(obj).data('value');
237
        if (status == 0) {
238
            cancel(id, obj);
239
        } else {
240
            restore(id, obj);
241
        }
242
    }
243
244
    function cancel(id, obj) {
245
        $.ajax({
246
            url: "/order/cancel",
247
            type: "POST",
248
            data: {
249
                "id": id,
250
            },
251
            dataType: 'json',
252
            success: function (data) {
253
                if (data.code == 2) {
254
                    $(obj).parents("tr").addClass('bg-danger');
255
                    $(obj).data('value', -1)
256
                    $(obj).text('恢复');
257
                } else {
258
                    alert(data.msg);
259
                }
260
                return false;
261
            }
262
        });
263
    }
264
265
    function restore(id, obj) {
266
        $.ajax({
267
            url: "/order/restore",
268
            type: "POST",
269
            data: {
270
                "id": id
271
            },
272
            dataType: 'json',
273
            success: function (data) {
274
                if (data.code == 2) {
275
                    $(obj).parents("tr").removeClass();
276
                    $(obj).parents("tr").addClass('text-center');
277
                    $(obj).data('value', 0);
278
                    $(obj).text('取消');
279
                } else {
280
                    alert(data.msg);
281
                }
282
                return false;
283
            }
284
        });
285
    }
286
287
    function commission(id, obj) {
288
        var is_commission = $(obj).data('value');
289
        if (is_commission == 0) {
290
            saveCommission(id, obj);
291
        } else {
292
            deleteCommission(is_commission, obj);
293
        }
294
    }
295
296
    function saveCommission(order_id, obj) {
297
        // console.log(id);
298
        $.get('/commission/infobyorderid', {
299
            'id': order_id,
300
        }, function (res) {
301
            // console.log(order_id);
302
            if (res.code == 2) {
303
                var data = res.data;
304
                $("#id").val(0);
305
                $("#order_id").val(order_id);
306
                $("#no").val(data.no);
307
                $("#contract_no").val(data.contract_no);
308
                $("#company_id").val(data.company_id);
309
                $("#company_name").val(data.company_name);
310
                $("#seller_id").val(data.seller_id);
311
                $("#seller_name").val(data.seller_name);
312
                $("#department_id").val(data.department_id);
313
                $("#department_name").val(data.department_name);
314
                $("#general_money").val(Number(data.general_money));
315
                $("#special_money").val(Number(data.special_money));
316
317
                $('#myModal').modal('show');
318
            }
319
        }, 'json');
320
    }
321
322
    function closeModel() {
323
        $("#form-commission")[0].reset();
324
        $('#myModal').modal('hide');
325
    }
326
327
    function doSave() {
328
        var jttime = $("#time").val();
329
        if (!jttime) {
330
            alert("请选择计提日期");
331
            return false;
332
        }
333
        var data = $("#form-commission").serializeArray();
334
        $.post('/commission/save', data, function (res) {
335
            if (res.code == 2) {
336
                alert('保存成功');
337
                $("#form-commission")[0].reset();
338
                $('#myModal').modal('hide');
339
                window.location.reload();
340
            } else {
341
                alert(res.msg);
342
            }
343
            return false;
344
        }, 'json');
345
        return false;
346
    }
347
348
    function deleteCommission(commission_id, obj) {
349
        if (confirm('确定删除此计提数据?')) {
350
            $.post('/commission/delete', {'id': commission_id}, function (res) {
351
                if (res.code == 2) {
352
                    alert("删除成功");
353
                    $(obj).attr('title', '计提');
354
                    $(obj).data('value', 0);
355
                    $(obj).children('span').text('否');
356
                    $(obj).children('span').removeClass('label-success');
357
                    $(obj).children('span').addClass('label-default');
358
                } else {
359
                    alert('删除失败!');
360
                }
361
            return false;
362
        }, 'json');
363
        }
364
        return false;
365
    }
366
367
</script>

+ 60 - 22
view/order/save.html

@ -1,5 +1,8 @@
1 1
{layout name="layout" /}
2 2
3
<link rel="stylesheet" href="/static/css/bootstrap-select.min.css">
4
<script src="/static/js/bootstrap-select.min.js"></script>
5
3 6
<nav class="breadcrumb">
4 7
    <span><a href="/" class="maincolor">首页</a></span>
5 8
    <span>&gt;</span>
@ -16,21 +19,21 @@
16 19
    <form role="form" id="form-order" action="" method="POST">
17 20
        <input type="hidden" name="id" id="id" value="{$data.id}">
18 21
        <div class="row">
19
            <div class="col-md-4">
22
            <div class="col-md-3">
20 23
                <div class="form-group">
21 24
                    <label for="name">序号</label>
22 25
                    <input type="text" class="form-control" name="no" id="no" value="{$data.no}"
23 26
                        placeholder="序号, 格式 MHTxx">
24 27
                </div>
25 28
            </div>
26
            <div class="col-md-4">
29
            <div class="col-md-3">
27 30
                <div class="form-group">
28 31
                    <label for="name">合同号</label>
29 32
                    <input type="text" class="form-control" name="contract_no" id="contract_no"
30 33
                        value="{$data.contract_no}" placeholder="合同号">
31 34
                </div>
32 35
            </div>
33
            <div class="col-md-4">
36
            <div class="col-md-3">
34 37
                <div class="form-group">
35 38
                    <label for="name">销售时间</label>
36 39
                    <input type="date" class="form-control" name="contract_time" id="contract_time"
@ -39,53 +42,66 @@
39 42
            </div>
40 43
        </div>
41 44
        <div class="row">
42
            <div class="col-md-4">
45
            <div class="col-md-3">
43 46
                <div class="form-group">
44 47
                    <label for="name">购货单位</label>
45
                    <input type="text" class="form-control" name="company_name" id="company_name"
46
                        value="{$data.company_name}" placeholder="购货单位">
48
                    <!-- <input type="text" class="form-control" name="company_name" id="company_name"
49
                        value="{//$data.company_name}" placeholder="购货单位"> -->
50
                    <select class="selectpicker form-control" data-live-search="true" name="company_id"
51
                        id="company_id">
52
                        <option value="0">请选择公司</option>
53
                        {foreach $companies as $key=>$value}
54
                            <option value="{$key}" {eq name="key" value="$data.company_id"}selected{/eq}>{$value}</option>
55
                        {/foreach}
56
                    </select>
47 57
                </div>
48 58
            </div>
49
            <div class="col-md-4">
59
            <div class="col-md-3">
50 60
                <div class="form-group">
51
                    <label for="name">部门</label>
52
                    <input type="text" class="form-control" name="department_name" id="department_name"
53
                        value="{$data.department_name}" placeholder="单价">
61
                    <label for="name">销售员</label>
62
                    <!-- <input type="text" class="form-control" name="seller_id" id="seller_id" value="{$data.seller_id}" placeholder="销售员"> -->
63
                        <select class="form-control" data-live-search="true" name="seller_id" id="seller_id">
64
                        <option value="0">请选择销售员</option>
65
                        {foreach $sellers as $key=>$value}
66
                            <option value="{$key}" {eq name="key" value="$data.seller_id"}selected{/eq}>{$value}</option>
67
                        {/foreach}
68
                    </select>
69
54 70
                </div>
55 71
            </div>
56
            <div class="col-md-4">
72
            <!-- <div class="col-md-3">
57 73
                <div class="form-group">
58
                    <label for="name">销售员</label>
59
                    <input type="text" class="form-control" name="seller_name" id="seller_name"
60
                        value="{$data.seller_name}" placeholder="销售员">
74
                    <label for="name">合同金额</label>
75
                    <input type="text" class="form-control" name="contract_money" id="contract_money"
76
                        value="{$data.consignor}" placeholder="发货人">
61 77
                </div>
62
            </div>
78
            </div> -->
63 79
        </div>
64 80
        <div class="row">
65
            <div class="col-md-4">
81
            <div class="col-md-3">
66 82
                <div class="form-group">
67 83
                    <label for="name">发货人</label>
68
                    <input type="number" class="form-control" name="consignor" id="consignor"
84
                    <input type="text" class="form-control" name="consignor" id="consignor"
69 85
                        value="{$data.consignor}" placeholder="发货人">
70 86
                </div>
71 87
            </div>
72
            <div class="col-md-4">
88
            <div class="col-md-3">
73 89
                <div class="form-group">
74 90
                    <label for="name">运费</label>
75
                    <input type="number" class="form-control" name="fare" id="fare" value="{$data.fare}"
91
                    <input type="number" class="form-control" name="fare" id="fare" value="{$data.fare|number_money}"
76 92
                        placeholder="运费">
77 93
                </div>
78 94
            </div>
79
            <div class="col-md-4">
95
            <div class="col-md-3">
80 96
                <div class="form-group">
81 97
                    <label for="name">代理费</label>
82
                    <input type="number" class="form-control" name="agency" id="agency" value="{$data.agency}"
98
                    <input type="number" class="form-control" name="agency" id="agency" value="{$data.agency|number_money}"
83 99
                        placeholder="代理费">
84 100
                </div>
85 101
            </div>
86 102
        </div>
87 103
        <div class="row">
88
            <div class="col-md-12">
104
            <div class="col-md-9">
89 105
                <div class="form-group">
90 106
                    <label for="name">备注</label>
91 107
                    <textarea class="form-control" name="remark" id="remark" rows="3">{$data.remark}</textarea>
@ -93,6 +109,28 @@
93 109
            </div>
94 110
        </div>
95 111
        <div class="row">
112
            <div class="col-md-3">
113
                <div class="form-group">
114
                    <label for="name">付款方式</label>
115
                    <input type="text" class="form-control" name="pay_type" id="pay_type"
116
                        value="{$data.pay_type}" placeholder="款到发货/月结/...">
117
                </div>
118
            </div>
119
            <div class="col-md-3">
120
                <div class="form-group">
121
                    <label for="name">到款金额</label>
122
                    <input type="number" class="form-control" name="payment" id="payment" value="{$data.payment|number_money}"
123
                        placeholder="运费">
124
                </div>
125
            </div>
126
            <div class="col-md-3">
127
                <div class="form-group">
128
                    <label for="name">到款时间</label>
129
                    <input type="date" class="form-control" name="pay_time" id="pay_time" value="{$data.pay_time}" placeholder="到款时间">
130
                </div>
131
            </div>
132
        </div>
133
        <div class="row mt-20">
96 134
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
97 135
                <input class="btn btn-default radius" type="button" value="&nbsp;&nbsp;取消&nbsp;&nbsp;"
98 136
                onClick="window.history.back();">

+ 207 - 118
view/order_item/index.html

@ -1,5 +1,8 @@
1 1
{layout name="layout" /}
2 2
3
<link rel="stylesheet" href="/static/css/bootstrap-select.min.css">
4
<script src="/static/js/bootstrap-select.min.js"></script>
5
3 6
<nav class="breadcrumb">
4 7
    <span><a href="/">首页</a></span>
5 8
    <span>&gt;</span>
@ -15,11 +18,12 @@
15 18
            <a href="javascript:save(0);" class="btn btn-primary radius">新增明细</a>
16 19
        </div>
17 20
    </div>
18
    <div class="col-md-11">
21
    <div class="col-md-12">
19 22
        <table class="table table-hover table-bordered table-condensed">
20 23
            <thead>
21 24
                <tr>
22
                    <th class="bg-info" colspan="16" style="text-align: left;">
25
                    <th class="bg-info" colspan="17" style="text-align: left;">
26
                        订单id:  {$orderInfo.id}|
23 27
                        购货单位: {$orderInfo.company_name} | 合同号: {$orderInfo.contract_no} | 时间: {$orderInfo.contract_time}
24 28
                    </th>
25 29
                </tr>
@ -27,7 +31,7 @@
27 31
                    <th>id</th>
28 32
                    <th>种类</th>
29 33
                    <th>产品名称</th>
30
                    <th>产品价格(公司价)</th>
34
                    <th>基准单价</th>
31 35
                    <th>销售数量(单位KG/台)</th>
32 36
                    <th>销售价格</th>
33 37
                    <th>合同金额</th>
@ -36,6 +40,7 @@
36 40
                    <th>成交金额</th>
37 41
                    <th>运费分摊</th>
38 42
                    <th>代理费分摊</th>
43
                    <th>其他费用</th>
39 44
                    <th>备注</th>
40 45
                    <th>状态</th>
41 46
                    <th>提成类型</th>
@ -45,10 +50,10 @@
45 50
            <tbody>
46 51
                {php}$types=['一般', '特批1', '特批2'];{/php}
47 52
                {foreach $list as $value}
48
                <tr>
53
                <tr class="text-center">
49 54
                    <td>{$value.id}</td>
50
                    <td>{$value.goods_category}</td>
51
                    <td>{$value.goods_name}</td>
55
                    <td class="text-left">{$value.goods_category_name}</td>
56
                    <td class="text-left">{$value.goods_name}</td>
52 57
                    <td>{$value.goods_price|format_money}</td>
53 58
                    <td>{$value.sales_amount}</td>
54 59
                    <td>{$value.sales_price|format_money}</td>
@ -58,6 +63,7 @@
58 63
                    <td>{$value.actual_money|format_money}</td>
59 64
                    <td>{$value.fare|format_money}</td>
60 65
                    <td>{$value.agency|format_money}</td>
66
                    <td>{$value.other_fee|format_money}</td>
61 67
                    <td>{$value.remark}</td>
62 68
                    <td class="td-status">{$value.status}</td>
63 69
                    <td>{$types[$value['type']]}</td>
@ -67,153 +73,236 @@
67 73
                    </td>
68 74
                </tr>
69 75
                {/foreach}
76
                <tr class="bg-info text-center">
77
                    <td>合计</td>
78
                    <td></td>
79
                    <td></td>
80
                    <td></td>
81
                    <td></td>
82
                    <td></td>
83
                    <td>{$orderInfo.contract_money|format_money}</td>
84
                    <td></td>
85
                    <td></td>
86
                    <td>{$orderInfo.actual_money|format_money}</td>
87
                    <td>{$orderInfo.fare|format_money}</td>
88
                    <td>{$orderInfo.agency|format_money}</td>
89
                    <td></td>
90
                    <td></td>
91
                    <td></td>
92
                    <td></td>
93
                    <td class="td-manager">
94
                        <a href="javascript:void(0);" onclick="save('{$value.id}')">修改</a>
95
                        <a href="javascript:void(0);" onclick="del('{$value.id}', this)">删除</a>
96
                    </td>
97
                </tr>
70 98
            </tbody>
71 99
        </table>
72 100
    </div>
73 101
</div>
74 102
75
<div class="modal" tabindex="-1" role="dialog" data-backdrop="false" id="myModal" aria-labelledby="myModalLabel" style="right: 10%;">
103
<div class="modal" tabindex="-1" role="dialog" data-backdrop="false" id="myModal" aria-labelledby="myModalLabel"
104
    style="right: 10%;">
76 105
    <div class="modal-dialog" role="document">
77
      <div class="modal-content">
78
        <div class="modal-header">
79
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
80
          <h4 class="modal-title">产品明细</h4>
81
        </div>
82
        <div class="modal-body">
83
            <form role="form" id="goods-form">
84
                <input type="hidden" name="id" id="id" value="0">
85
                <input type="hidden" name="order_id" id="order_id" value="{$order_id}">
86
                <div class="row">
87
                    <div class="col-md-4">
88
                        <div class="form-group">
89
                            <label for="name">产品类别</label>
90
                            <input type="text" class="form-control" name="goods_category" id="goods_category" placeholder="产品类别">
106
        <div class="modal-content">
107
            <div class="modal-header">
108
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
109
                        aria-hidden="true">&times;</span></button>
110
                <h4 class="modal-title">产品明细</h4>
111
            </div>
112
            <div class="modal-body">
113
                <form role="form" id="goods-form">
114
                    <input type="hidden" name="id" id="id" value="0">
115
                    <input type="hidden" name="order_id" id="order_id" value="{$order_id}">
116
                    <div class="row">
117
                        <div class="col-md-4">
118
                            <div class="form-group">
119
                                <label for="name">产品名称</label>
120
                                <!-- <input type="text" class="form-control" name="goods_name" id="goods_name" placeholder="产品名称"> -->
121
                                <select class="selectpicker form-control" data-live-search="true" name="goods_id"
122
                                    id="goods_id">
123
                                    <option value="0">请选择产品</option>
124
                                    {foreach $goodsSubtotalList as $key=>$value}
125
                                    <optgroup label="{$value.goods_category_name}">
126
                                        {noempty name="value.items"}
127
                                        {foreach $value.items as $val}
128
                                        <option value="{$val.id}">{$val.name}</option>
129
                                        {/foreach}
130
                                        {/noempty}
131
                                    </optgroup>
132
                                    {/foreach}
133
                                </select>
134
                            </div>
91 135
                        </div>
92
                    </div>
93
                    <div class="col-md-4">
94
                        <div class="form-group">
95
                            <label for="name">产品名称</label>
96
                            <input type="text" class="form-control" name="goods_name" id="goods_name" placeholder="产品名称">
136
                        <div class="col-md-4">
137
                            <div class="form-group">
138
                                <label for="name">产品价格(公司低价)</label>
139
                                <input type="text" class="form-control" name="goods_price" id="goods_price"
140
                                    placeholder="产品价格">
141
                                <input type="hidden" name="goods_name" id="goods_name" value="">
142
                                <input type="hidden" name="goods_category_id" id="goods_category_id" value="">
143
                                <input type="hidden" name="goods_category_name" id="goods_category_name" value="">    
144
                            </div>
97 145
                        </div>
98
                    </div>
99
                    <div class="col-md-4">
100
                        <div class="form-group">
101
                            <label for="name">产品价格(公司低价)</label>
102
                            <input type="text" class="form-control" name="goods_price" id="goods_price" placeholder="产品价格">
146
                        <div class="col-md-4">
147
                            <div class="form-group">
148
                                <label for="name">提成类型</label>
149
                                <div class="mt-5">
150
                                    <label class="radio-inline">
151
                                        <input type="radio" name="type" id="type0" value="0" checked="checked"> 一般
152
                                    </label>
153
                                    <label class="radio-inline">
154
                                        <input type="radio" name="type" id="type1" value="1"> 特批1
155
                                    </label>
156
                                    <label class="radio-inline">
157
                                        <input type="radio" name="type" id="type2" value="2"> 特批2
158
                                    </label>
159
                                </div>
160
                            </div>
103 161
                        </div>
104 162
                    </div>
105
                </div>
106
                <div class="row">
107
                    <div class="col-md-4">
108
                        <div class="form-group">
109
                            <label for="name">销售数量(KG/台)</label>
110
                            <input type="number" class="form-control val_change" name="sales_amount" id="sales_amount" placeholder="数量">
163
                    <div class="row">
164
                        <div class="col-md-4">
165
                            <div class="form-group">
166
                                <label for="name">销售数量(KG/台)</label>
167
                                <input type="number" class="form-control s_val_change" name="sales_amount"
168
                                    id="sales_amount" placeholder="数量">
169
                            </div>
111 170
                        </div>
112
                    </div>
113
                    <div class="col-md-4">
114
                        <div class="form-group">
115
                            <label for="name">销售单价</label>
116
                            <input type="number" class="form-control val_change" name="sales_price" id="sales_price" placeholder="单价">
171
                        <div class="col-md-4">
172
                            <div class="form-group">
173
                                <label for="name">销售单价</label>
174
                                <input type="number" class="form-control s_val_change" name="sales_price" id="sales_price"
175
                                    placeholder="单价">
176
                            </div>
117 177
                        </div>
118
                    </div>
119
                    <div class="col-md-4">
120
                        <div class="form-group">
121
                            <label for="name">总金额</label>
122
                            <input type="number" class="form-control" name="" id="sales_money" placeholder="总金额">
178
                        <div class="col-md-4">
179
                            <div class="form-group">
180
                                <label for="name">总金额</label>
181
                                <input type="number" class="form-control" name="sales_money" id="sales_money" placeholder="总金额"
182
                                    disabled>
183
                            </div>
123 184
                        </div>
124 185
                    </div>
125
                </div>
126
                <div class="row">
127
                    <div class="col-md-4">
128
                        <div class="form-group">
129
                            <label for="name">实际发货量(KG/台)</label>
130
                            <input type="number" class="form-control val_change" name="actual_amount" id="actual_amount" placeholder="数量">
186
                    <div class="row">
187
                        <div class="col-md-4">
188
                            <div class="form-group">
189
                                <label for="name">实际发货量(KG/台)</label>
190
                                <input type="number" class="form-control a_val_change" name="actual_amount"
191
                                    id="actual_amount" placeholder="数量">
192
                            </div>
131 193
                        </div>
132
                    </div>
133
                    <div class="col-md-4">
134
                        <div class="form-group">
135
                            <label for="name">实际成交价</label>
136
                            <input type="number" class="form-control val_change" name="actual_price" id="actual_price" placeholder="单价">
194
                        <div class="col-md-4">
195
                            <div class="form-group">
196
                                <label for="name">实际成交价</label>
197
                                <input type="number" class="form-control a_val_change" name="actual_price"
198
                                    id="actual_price" placeholder="单价">
199
                            </div>
137 200
                        </div>
138
                    </div>
139
                    <div class="col-md-4">
140
                        <div class="form-group">
141
                            <label for="name">总金额</label>
142
                            <input type="number" class="form-control" name="" id="actual_money" placeholder="总金额">
201
                        <div class="col-md-4">
202
                            <div class="form-group">
203
                                <label for="name">总金额</label>
204
                                <input type="number" class="form-control" name="actual_money" id="actual_money" placeholder="总金额"
205
                                    disabled>
206
                            </div>
143 207
                        </div>
144 208
                    </div>
145
                </div>
146
                <div class="row">
147
                    <div class="col-md-4">
148
                        <div class="form-group">
149
                            <label for="name">代理费分摊</label>
150
                            <input type="number" class="form-control val_change" name="agency" id="agency" placeholder="代理费">
209
                    <div class="row">
210
                        <div class="col-md-4">
211
                            <div class="form-group">
212
                                <label for="name">代理费分摊</label>
213
                                <input type="number" class="form-control" name="agency" id="agency"
214
                                    placeholder="代理费">
215
                            </div>
151 216
                        </div>
152
                    </div>
153
                    <div class="col-md-4">
154
                        <div class="form-group">
155
                            <label for="name">运费分摊</label>
156
                            <input type="number" class="form-control val_change" name="fare" id="fare" placeholder="运费">
217
                        <div class="col-md-4">
218
                            <div class="form-group">
219
                                <label for="name">运费分摊</label>
220
                                <input type="number" class="form-control" name="fare" id="fare"
221
                                    placeholder="运费">
222
                            </div>
157 223
                        </div>
158
                    </div>
159
                    <div class="col-md-4">
160
                        <div class="form-group">
161
                            <label for="name">提成类型</label>
162
                            <div class="mt-5">
163
                                <label class="radio-inline">
164
                                    <input type="radio" name="type" id="type0" value="0" checked="checked"> 一般
165
                                </label>
166
                                <label class="radio-inline">
167
                                    <input type="radio" name="type" id="type1" value="1"> 特批1
168
                                </label>
169
                                <label class="radio-inline">
170
                                    <input type="radio" name="type" id="type2" value="2"> 特批2
171
                                </label>
224
                        <div class="col-md-4">
225
                            <div class="form-group">
226
                                <label for="name">其他费用</label>
227
                                <input type="number" class="form-control" name="other_fee" id="other_fee"
228
                                    placeholder="其他费用">
172 229
                            </div>
173 230
                        </div>
174 231
                    </div>
175
                </div>
176
                <div class="row">
177
                    <div class="col-md-12">
178
                        <div class="form-group">
179
                            <label for="name">备注</label>
180
                            <textarea class="form-control"  name="remark" id="remark"  rows="3"></textarea>
232
                    <div class="row">
233
                        <div class="col-md-12">
234
                            <div class="form-group">
235
                                <label for="name">备注</label>
236
                                <textarea class="form-control" name="remark" id="remark" rows="3"></textarea>
237
                            </div>
181 238
                        </div>
182 239
                    </div>
183
                </div>
184
            </form>
185
        </div>
186
        <div class="modal-footer">
187
          <button type="button" class="btn btn-default"  onclick="closeModel()">Close</button>
188
          <button type="button" class="btn btn-success" onclick="doSave()">Save</button>
189
        </div>
190
      </div><!-- /.modal-content -->
240
                </form>
241
            </div>
242
            <div class="modal-footer">
243
                <button type="button" class="btn btn-default" onclick="closeModel()">Close</button>
244
                <button type="button" class="btn btn-success" onclick="doSave()">Save</button>
245
            </div>
246
        </div><!-- /.modal-content -->
191 247
    </div><!-- /.modal-dialog -->
192
  </div><!-- /.modal -->
193
248
</div><!-- /.modal -->
194 249
195 250
<script>
251
    $("#goods_id").change(function () {
252
        // console.log($("#goods_id").val());
253
        var goods_id = $("#goods_id").val();
254
        $.get('/goods/info/' + goods_id, null, function (res) {
255
            var data = res.data;
256
            console.log(data);
257
            $("#goods_price").val((data.price/100).toFixed(2));
258
            $("#goods_name").val(data.name);
259
            $("#goods_category_id").val(data.category_id);
260
            $("#goods_category_name").val(data.category_name);
261
            $("input[type='radio'][name='type']").prop("checked", false);
262
            $("input[type='radio'][name='type'][value='" + data.type + "']").prop("checked", true);
263
        }, 'json');
264
    })
265
266
    $(".s_val_change").change(function(){
267
        var sales_amount = Number($("#sales_amount").val());
268
        var sales_price = Number($("#sales_price").val());
269
        var sales_money = sales_amount*sales_price;
270
        $("#sales_money").val(sales_money.toFixed(2));
271
    })
272
273
    $(".a_val_change").change(function(){
274
        var actual_amount = Number($("#actual_amount").val());
275
        var actual_price = Number($("#actual_price").val());
276
        var actual_money = actual_amount*actual_price;
277
        $("#actual_money").val(actual_money.toFixed(2));
278
    })
279
196 280
    function save(id) {
197
        console.log(id);
281
        // console.log(id);
198 282
        if (id) {
199
            $.get('/order/iteminfo', {
283
            $.get('/order_item/info', {
200 284
                'id': id,
201
            }, function(res) {
285
            }, function (res) {
202 286
                if (res.code == 2) {
203 287
                    var data = res.data;
204 288
                    $("#id").val(data.id);
205 289
                    $("#order_id").val(data.order_id);
206
                    $("#goods_category").val(data.goods_category);
290
                    $('.selectpicker').selectpicker('val', data.goods_id);
291
                    $("#goods_category_id").val(data.goods_category_id);
292
                    $("#goods_category_name").val(data.goods_category_name);
207 293
                    $("#goods_name").val(data.goods_name);
208
                    $("#goods_price").val(data.goods_price);
294
                    $("#goods_price").val(data.goods_price/100);
209 295
                    $("#sales_amount").val(data.sales_amount);
210
                    $("#sales_price").val(data.sales_price);
296
                    $("#sales_price").val(data.sales_price/100);
297
                    $("#sales_money").val(data.sales_money/100);
211 298
                    $("#actual_amount").val(data.actual_amount);
212
                    $("#actual_price").val(data.actual_price);
213
                    $("#agency").val(data.agency);
214
                    $("#fare").val(data.fare);
215
                    $("input[type='radio'][name='type']").prop("checked",false);
216
                    $("input[type='radio'][name='type'][value='"+data.type+"']").prop("checked",true);
299
                    $("#actual_price").val(data.actual_price/100);
300
                    $("#actual_money").val(data.actual_money/100);
301
                    $("#agency").val(data.agency/100);
302
                    $("#fare").val(data.fare/100);
303
                    $("#other_fee").val(data.other_fee/100);
304
                    $("input[type='radio'][name='type']").prop("checked", false);
305
                    $("input[type='radio'][name='type'][value='" + data.type + "']").prop("checked", true);
217 306
                    $("#remark").val(data.remark);
218 307
                }
219 308
            }, 'json');
@ -231,7 +320,7 @@
231 320
232 321
    function doSave() {
233 322
        var data = $("#goods-form").serializeArray();
234
        $.post('/order/itemsave', data, function(res) {
323
        $.post('/order_item/save', data, function (res) {
235 324
            if (res.code == 2) {
236 325
                alert('保存成功');
237 326
                $("#goods-form")[0].reset();
@ -247,13 +336,13 @@
247 336
248 337
    function del(id, obj) {
249 338
        $.ajax({
250
            url: "/order/itemdelete",
339
            url: "/order_item/delete",
251 340
            type: "POST",
252 341
            data: {
253 342
                "id": id
254 343
            },
255 344
            dataType: 'json',
256
            success: function(data) {
345
            success: function (data) {
257 346
                if (data.code == 2) {
258 347
                    $(obj).parents("tr").remove();
259 348
                } else {