hrjy 2 years ago
parent
commit
e507690eb9

+ 5 - 0
app/admin/controller/user/UserGroup.php

@@ -52,8 +52,10 @@ class UserGroup extends AuthController
         $f = array();
         if (!$group) {
             $f[] = Form::input('group_name', '分组名称', '');
+            $f[] = Form::number('discount', '折扣', '');
         } else {
             $f[] = Form::input('group_name', '分组名称', $group->getData('group_name'));
+            $f[] = Form::input('discount', '折扣', $group->getData('discount'));
         }
         $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('saveGroup', array('id' => $id)));
         $this->assign(compact('form'));
@@ -68,7 +70,10 @@ class UserGroup extends AuthController
     {
         $data = UtilService::postMore([
             ['group_name', ''],
+            ['discount', ''],
         ]);
+        if (!$data['discount']) return JsonService::fail('请输入折扣');
+        if (!$data['group_name']) return JsonService::fail('请输入分组名称');
         if ($id) {
             if (GroupModel::where('id', $id)->update($data)) {
                 return JsonService::success('修改成功');

+ 2 - 1
app/admin/view/user/user_group/index.php

@@ -36,7 +36,8 @@
     layList.tableList('List', "{:Url('groupList')}", function () {
         return [
             {field: 'id', title: 'ID', sort: true, event: 'id', width: '20%'},
-            {field: 'group_name', title: '分组名称', width: '60%'},
+            {field: 'group_name', title: '分组名称', width: '50%'},
+            {field: 'discount', title: '折扣', width: '10%'},
             {field: 'right', title: '操作', align: 'center', toolbar: '#act', width: '20%'},
         ];
     });

+ 23 - 3
app/api/controller/water/WaterQueryController.php

@@ -3,6 +3,7 @@
 namespace app\api\controller\water;
 
 use app\admin\model\sms\SmsRecord;
+use app\admin\model\user\UserGroup;
 use app\admin\model\water\WaterCate;
 use app\admin\model\water\WaterMaterial;
 use app\admin\model\water\WaterMaterialScience;
@@ -49,6 +50,7 @@ class WaterQueryController
 //            }
 //        }
         //顶板
+        $data['uid'] = $request->uid();
         $calculation = $this->calculation($data);
         $amount = $this->AmountOfMoney($calculation, $data);// 计算总价,表格
         Db::startTrans();
@@ -115,6 +117,11 @@ class WaterQueryController
 
     public function AmountOfMoney($calculation, $data)
     {
+        $user = User::where('uid', $data['uid'])->find();
+        $discount = 0;
+        if ($user['group_id'] > 0){
+            $discount = UserGroup::where('id', $user['group_id'])->value('discount');
+        }
         $table = [];
         $zj = 0; //总价
         $zzl = 0; // 总重量
@@ -200,7 +207,7 @@ class WaterQueryController
         $lac_storey = 0;
         foreach ($calculation['lacing_number'] as $v){
             $lac_storey ++;
-            $details = WaterMaterialScience::where('cate_id', $data['lacing'][$lac_storey-1])->where([['long', '=', 4], ['wide', '=', 4]])->where($where)->find();
+            $details = WaterMaterialScience::where('cate_id', $data['lacing'][$lac_storey-1])->where($where)->find();
             $zj += $details['unit_price'] * $v;
             $zzl += $details['weight'] * $v;
             $table[] = ['title' => '主拉B'.$lac_storey.'层' , 'name' => $details['name'], 'specifications' => '1', 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 3];
@@ -210,7 +217,7 @@ class WaterQueryController
         $fula_storey = 0;
         foreach ($calculation['fula_number'] as $v){
             $fula_storey ++;
-            $details = WaterMaterialScience::where('cate_id', $data['fula'][$fula_storey-1])->where([['long', '=', 4], ['wide', '=', 4]])->where($where)->find();
+            $details = WaterMaterialScience::where('cate_id', $data['fula'][$fula_storey-1])->where($where)->find();
             $zj += $details['unit_price'] * $v;
             $zzl += $details['weight'] * $v;
             $table[] = ['title' => '辅拉B'.$fula_storey.'层' , 'name' => $details['name'], 'specifications' => '1', 'number' => $v, 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $v, 'weight' => $details['weight'] * $v , 'type' => 6];
@@ -257,11 +264,24 @@ class WaterQueryController
             $zzl += $details['weight'] * $calculation['ladder'];
             $table[] = ['title' => '扶梯' , 'name' => $details['name'], 'specifications' => '1', 'number' => $calculation['ladder'], 'unit_price' => $details['unit_price'], 'company' => $details['company'], 'ot_price' => $details['unit_price'] * $calculation['ladder'], 'weight' => $details['weight'] * $calculation['ladder'] , 'type' => 9];
         }
+
         foreach ($table as &$i){
             $i['ot_price'] = round($i['ot_price'], 2);
         }
+        if ($discount > 0){
+
+            foreach ($table as &$item)
+            {
+                $item['unit_price'] = $item['unit_price'] * $discount;
+                $item['ot_price'] = $item['ot_price'] * $discount;
+            }
+            return ['table' => $table, 'zj' => $zj * $discount, 'zzl' => $zzl];
+        }else{
+            return ['table' => $table, 'zj' => $zj, 'zzl' => $zzl];
+        }
+
+
 
-        return ['table' => $table, 'zj' => $zj, 'zzl' => $zzl];
 
     }