Browse Source

Merge branch 'master' of http://gits.hdlkeji.com:3000/zhangguidong/chuyu

wanglu 2 years ago
parent
commit
b429599a5a

+ 3 - 1
.gitignore

@@ -5,4 +5,6 @@ public/myapi.html
 /vendor/
 composer.lock
 public/pay_log.log
-public/uploads/
+public/uploads/
+.htaccess
+nginx.htaccess

+ 158 - 17
application/admin/controller/user/User.php

@@ -4,6 +4,7 @@ namespace app\admin\controller\user;
 
 use AlibabaCloud\Client\Request\UserAgent;
 use AlibabaCloud\Ecs\V20140526\UnassignIpv6Addresses;
+use app\admin\model\UserRemarks;
 use app\common\controller\Backend;
 use app\common\library\Auth;
 use fast\Random;
@@ -33,6 +34,7 @@ class User extends Backend
         parent::_initialize();
         $this->model = model('User');
         $this->view->assign("levelList", $this->model->getLevelList());
+        $this->view->assign("bindRemarksList", $this->model->bindRemarksList());
     }
 
     /**
@@ -91,14 +93,52 @@ class User extends Backend
                     }
 
                     // 复制数据
-                    $c_user_ids = explode(',', $params['c_user_id']);
-                    unset($params['c_user_id']);
+//                    if (isset($params['c_user_id'])){
+//                        $c_user_ids = explode(',', $params['c_user_id']);
+//                        unset($params['c_user_id']);
+//                    }
+
+                    //添加备注信息
+                    if ($params['type'] == 1) {
+                        // 商家备注:1=回收备注,2=餐具备注,3=商城备注
+                        for ($i = 1; $i <= 3; $i++) {
+                            $has_add_relations[$i] = false;
+                            $param_remarks = "remarks" . $i;
+                            if ($params[$param_remarks]) {
+                                $user_remarks = UserRemarks::where('value', $params[$param_remarks])->where('type', $i)->find();
+                                if (!empty($user_remarks)) {
+                                    $params[$param_remarks] = $user_remarks->id;
+                                    $has_add_relations[$i] = true; //原有备注,要查看B端账号,绑定
+                                } else {
+                                    $user_remarks_insert = new UserRemarks;
+                                    $user_remarks_insert->type = $i;
+                                    $user_remarks_insert->value = $params[$param_remarks];
+                                    $user_remarks_insert->save();
+                                    // 获取自增ID
+                                    $params[$param_remarks] = $user_remarks_insert->id;
+                                }
+                            }
+                        }
+                    }
+
+                    if ($params['type'] == 2 && $params['type_remarks'] != "" && $params['bind_remarks'] != "") {
+                        //查询绑定过商户 list  当前备注的商户
+                        $column_remarks = 'remarks' . $params['type_remarks'];
+                        $remarks_list_user = $this->model->where($column_remarks, $params['bind_remarks'])->select();
+                        //$remarks_list_user = $this->model->where(['type_remarks' => $params['type_remarks'], 'bind_remarks' => $params['bind_remarks']])->select();
+                        if (count($remarks_list_user) > 0) {
+                            foreach ($remarks_list_user as $v) {
+                                $c_user_ids[] = $v['id'];
+                            }
+                        }
+                    }
 
                     $insert_user_id = model('user')->insert($params, false, true);
-                    // 添加关联关系
-                    if ($params['type'] == 2) {
-                        // todo 服务关系是否之前存在过 ,状态:0=未服务,1=已服务,2=已注销
 
+                    // 添加关联关系 -- 添加回收员or配送员时
+                    if ($params['type'] == 2 && $params['type_remarks'] != "" && $params['bind_remarks'] != "") {
+                        // todo 服务关系是否之前存在过 ,状态:0=未服务,1=已服务,2=已注销
+                        // 直接绑定商户时
                         if (count($c_user_ids) > 0) {
                             foreach ($c_user_ids as $v) {
                                 $user_relations[] = [
@@ -109,6 +149,24 @@ class User extends Backend
                             }
                             model('user_relations')->insertAll($user_relations);
                         }
+                    } elseif ($params['type'] == 1) {
+                        for ($i = 1; $i <= 3; $i++) {
+                            if ($has_add_relations[$i]) {
+                                $param_remarks = "remarks" . $i;
+                                // 添加商家时,查看回收员or配送员是否已绑定过该备注,绑定会员关系
+                                $user_b_list = $this->model->where(['type_remarks' => $i, 'bind_remarks' => $params[$param_remarks]])->order('id', 'desc')->select();
+                                if (count($user_b_list) > 0) {
+                                    foreach ($user_b_list as $user_b) {
+                                        $user_relations[] = [
+                                            'c_user_id' => $insert_user_id,
+                                            'b_user_id' => $user_b['id'],
+                                            'b_level' => $user_b['level'],
+                                        ];
+                                    }
+                                    model('user_relations')->insertAll($user_relations);
+                                }
+                            }
+                        }
                     }
 
                     Db::commit();
@@ -144,17 +202,44 @@ class User extends Backend
         if (false === $this->request->isPost()) {
             $row['c_user_id'] = '';
             // 查询和商家的关联数据显示
+            if ($row['type'] == 1) {
+                // 商家备注:1=回收备注,2=餐具备注,3=商城备注
+                for ($i = 1; $i <= 3; $i++) {
+                    $param_remarks = "remarks" . $i;
+                    if ($row[$param_remarks]) {
+                        $user_remarks = UserRemarks::where('id', $row[$param_remarks])->where('type', $i)->find();
+                        if (!empty($user_remarks)) {
+                            $row[$param_remarks] = $user_remarks->value;
+                        } else {
+                            $row[$param_remarks] = "";
+                        }
+                    }
+                }
+            }
+
+            $row['user_remarks'] = [];
             if ($row['type'] == 2) {
-                $user_relations_list = model('user_relations')
-                    ->field('c_user_id')
-                    ->where(['b_user_id' => $row['id'], 'b_level' => $row['level']])
-                    ->select();
-                $ids = [];
-                foreach ($user_relations_list as $v) {
-                    $ids[] = $v['c_user_id'];
+                // 直接绑定时
+//                $user_relations_list = model('user_relations')
+//                    ->field('c_user_id')
+//                    ->where(['b_user_id' => $row['id'], 'b_level' => $row['level']])
+//                    ->select();
+//                $ids = [];
+//                foreach ($user_relations_list as $v) {
+//                    $ids[] = $v['c_user_id'];
+//                }
+//
+//                $row['c_user_id'] = implode(',', $ids);
+                // 绑定过商户的备注
+                if ($row['type_remarks']) {
+                    $user_remarks_model = new UserRemarks();
+                    $row['user_remarks'] = $user_remarks_model->alias('remarks')->join('user u ', 'u.remarks' . $row['type_remarks'] . '=remarks.id')
+                        ->where(['remarks.type' => $row['type_remarks'], 'u.type' => 1])
+                        ->field('remarks.id,remarks.value,remarks.type')
+                        ->group('remarks.id')
+                        ->select();
                 }
 
-                $row['c_user_id'] = implode(',', $ids);
             }
 
             $this->view->assign('row', $row);
@@ -178,10 +263,65 @@ class User extends Backend
                 $row->validateFailException()->validate($validate);
             }
 
+            $params_c_user_ids = $db_c_user_ids = [];
             if ($row['type'] == 2) {
                 // 处理 c_user_id
-                $params_c_user_ids = explode(',', $params['c_user_id']);
-                unset($params['c_user_id']);
+//                $params_c_user_ids = explode(',', $params['c_user_id']);
+//                unset($params['c_user_id']);
+                //查询商户 list // 绑定过 当前备注的商户
+                $column_remarks = 'remarks' . $params['type_remarks'];
+                $remarks_list_user = $this->model->where($column_remarks, $params['bind_remarks'])->select();
+                foreach ($remarks_list_user as $vrlu) {
+                    $params_c_user_ids[] = $vrlu['id'];
+                }
+            }
+
+            //添加备注信息
+            if ($row['type'] == 1) {
+                // 商家备注:1=回收备注,2=餐具备注,3=商城备注
+                for ($i = 1; $i <= 3; $i++) {
+                    $param_remarks = "remarks" . $i;
+                    $del_relations = false;
+                    if ($params[$param_remarks]) {
+                        $user_remarks = UserRemarks::where('value', $params[$param_remarks])->where('type', $i)->find();
+                        if (!empty($user_remarks)) {
+                            $params[$param_remarks] = $user_remarks->id;
+                            if ($params[$param_remarks] != $row[$param_remarks]) {
+                                // 原有绑定id变化--需要删除旧的C-B关系 && 绑定新关系
+                                $del_relations = true;
+                                // 绑定新关系
+                                $user_b_list = $this->model->where(['type_remarks' => $i, 'bind_remarks' => $params[$param_remarks]])->order('id', 'desc')->select();
+                                if(count($user_b_list)>0){
+                                    foreach ($user_b_list as $user_b){
+                                        $user_relation[] = [
+                                            'c_user_id' => $row['id'],
+                                            'b_user_id' => $user_b['id'],
+                                            'b_level' => $user_b['level'],
+                                        ];
+                                    }
+                                    model('user_relations')->insertAll($user_relation);
+                                }
+                            }
+                        } else {
+                            $user_remarks_insert = new UserRemarks;
+                            $user_remarks_insert->type = $i;
+                            $user_remarks_insert->value = $params[$param_remarks];
+                            $user_remarks_insert->save();
+                            // 获取自增ID
+                            $params[$param_remarks] = $user_remarks_insert->id;
+
+                            $del_relations = true;
+                        }
+                    }
+                    //删除旧关系
+                    if ($row[$param_remarks] != 0 && $del_relations) {
+                        $user_b = $this->model->where(['type_remarks' => $i, 'bind_remarks' => $row[$param_remarks]])->order('id', 'desc')->select();
+                        foreach ($user_b as $vub){
+                            $user_b_ids[] = $vub['id'];
+                        }
+                        model('user_relations')->where('c_user_id',$row['id'])->whereIn('b_user_id',$user_b_ids)->delete();
+                    }
+                }
             }
 
             $result = $row->allowField(true)->save($params);
@@ -263,8 +403,8 @@ class User extends Backend
         Db::startTrans();
         try {
 
-            $password =$this->getEncryptPassword( '123456',$row['salt']);
-            Db::name('user')->where('id',$ids)->update(['password'=>$password]);
+            $password = $this->getEncryptPassword('123456', $row['salt']);
+            Db::name('user')->where('id', $ids)->update(['password' => $password]);
             Db::commit();
         } catch (\Exception $e) {
             Db::rollback();
@@ -272,6 +412,7 @@ class User extends Backend
         }
         $this->success("重置成功");
     }
+
     public function getEncryptPassword($password, $salt = '')
     {
         return md5(md5($password) . $salt);

+ 34 - 4
application/admin/controller/user/UserCommon.php

@@ -5,6 +5,7 @@ namespace app\admin\controller\user;
 
 
 use app\admin\model\UserRelations;
+use app\admin\model\UserRemarks;
 use app\common\controller\Backend;
 
 class UserCommon extends Backend
@@ -60,10 +61,10 @@ class UserCommon extends Backend
         //设置过滤方法
         $this->request->filter(['strip_tags', 'trim']);
         if ($this->request->isAjax()) {
-//            //如果发送的来源是Selectpage,则转发到Selectpage
-//            if ($this->request->request('keyField')) {
-//                return $this->selectpage();
-//            }
+            //如果发送的来源是Selectpage,则转发到Selectpage
+            if ($this->request->request('keyField')) {
+                return $this->selectpage();
+            }
 
             $where['level'] = $this->request->get('level');
             $where['type'] = $this->request->get('type');
@@ -124,4 +125,33 @@ class UserCommon extends Backend
             return $this->success('ok', null, ['list' => $list]);
         }
     }
+
+    /***
+     * 通过备注类型,获得备注详细信息
+     */
+    public function remarks_list()
+    {
+        //设置过滤方法
+        $this->request->filter(['strip_tags', 'trim']);
+        if ($this->request->isAjax()) {
+
+            $type_remarks = $this->request->post('type_remarks');
+
+            // 获取 c商户 备注过的备注信息
+            $user_remarks_model = new UserRemarks();
+            //$list = $user_remarks_model->where(['type' => $type_remarks])->select(); // 所有数据
+            // 绑定过商户的
+            $list = $user_remarks_model->alias('remarks')->join('user u ', 'u.remarks' . $type_remarks . '=remarks.id')
+                ->where(['remarks.type' => $type_remarks, 'u.type' => 1])
+                ->field('remarks.id,remarks.value,remarks.type')
+                ->group('remarks.id')
+                ->select();
+
+            if (count($list) == 0) {
+                return $this->error('no');
+            }
+
+            return $this->success('ok', null, ['list' => $list]);
+        }
+    }
 }

+ 4 - 1
application/admin/lang/zh-cn/user/user.php

@@ -35,10 +35,13 @@ return [
     'Level 3' => '配送员',
     'City' => '省市区',
     'Address' => '地址',
-    'Bind merchants' => '绑定商家',
+    'Bind merchants' => '绑定商家备注',
     'Cancelshop' => '商家注销',
     'Cancelshop 0' => '正常',
     'Cancelshop 1' => '已注销',
     'Remarks' => '备注',
     'Reset Password' => '重置密码',
+    'Remarks1' => '回收备注',
+    'Remarks2' => '餐具备注',
+    'Remarks3' => '商城备注',
 ];

+ 6 - 0
application/admin/model/User.php

@@ -77,6 +77,12 @@ class User extends Model
         return ['1' => __('Level 1'), '2' => __('Level 2'), '3' => __('Level 3')];
     }
 
+    // 1回收备注 2餐具备注 3商城备注
+    public function bindRemarksList()
+    {
+        return ['1' => __('Remarks1'), '2' => __('Remarks2'), '3' => __('Remarks3')];
+    }
+
 
     public function getPrevtimeTextAttr($value, $data)
     {

+ 27 - 0
application/admin/model/UserRemarks.php

@@ -0,0 +1,27 @@
+<?php
+
+
+namespace app\admin\model;
+
+use think\Model;
+
+
+class UserRemarks extends Model
+{
+
+
+    // 表名
+    protected $name = 'user_remarks';
+
+    // 定义时间戳字段名
+    protected $createTime = false;
+    protected $updateTime = false;
+    protected $deleteTime = false;
+
+    // 追加属性
+    protected $append = [
+
+    ];
+
+
+}

+ 39 - 7
application/admin/view/user/user/add.html

@@ -49,15 +49,40 @@
     <div class="form-group hidden" id="div_c-c_user_id">
         <label class="control-label col-xs-12 col-sm-2">{:__('Bind merchants')}:</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-c_user_id" data-source="user/user_common/user_level?level=1&type=1"
-                   data-field="nickname" data-multiple="true" data-pagination="false"
-                   class="form-control selectpage" name="row[c_user_id]" type="text" value="">
+            <select id="c-type_remarks" min="0" class="selectpicker" name="row[type_remarks]" >
+                <option value="" >--请选择备注类型--</option>
+                {foreach name="bindRemarksList" item="vo"}
+                <option value="{$key}" {in name="key" value="0" }selected{
+                /in}>{$vo}</option>
+                {/foreach}
+            </select>
+
+            <select id="c-bind_remarks" min="0" class="selectpicker"  name="row[bind_remarks]"  >
+                <option value="" >--请选择备注--</option>
+            </select>
+<!--            <input id="c-c_user_id" data-source="user/user_common/user_level?level=1&type=1"-->
+<!--                   data-field="nickname" data-multiple="true" data-pagination="false"-->
+<!--                   class=" selectpage" name="row[c_user_id]" type="text" value="">-->
         </div>
     </div>
-    <div class="form-group">
-        <label for="remarks" class="control-label col-xs-12 col-sm-2">{:__('Remarks')}:</label>
-        <div class="col-xs-12 col-sm-8">
-            <input type="text" class="form-control" id="remarks" name="row[remarks]" autocomplete="off" value="" />
+    <div id="div_c_remarks">
+        <div class="form-group">
+            <label for="remarks1" class="control-label col-xs-12 col-sm-2">{:__('Remarks1')}:</label>
+            <div class="col-xs-12 col-sm-8">
+                <input type="text" class="form-control" id="remarks1" name="row[remarks1]" autocomplete="off" value="" />
+            </div>
+        </div>
+        <div class="form-group">
+            <label for="remarks2" class="control-label col-xs-12 col-sm-2">{:__('Remarks2')}:</label>
+            <div class="col-xs-12 col-sm-8">
+                <input type="text" class="form-control" id="remarks2" name="row[remarks2]" autocomplete="off" value="" />
+            </div>
+        </div>
+        <div class="form-group">
+            <label for="remarks3" class="control-label col-xs-12 col-sm-2">{:__('Remarks3')}:</label>
+            <div class="col-xs-12 col-sm-8">
+                <input type="text" class="form-control" id="remarks3" name="row[remarks3]" autocomplete="off" value="" />
+            </div>
         </div>
     </div>
     <div class="form-group" id="div_c-city">
@@ -72,6 +97,13 @@
             <input type="text" class="form-control" id="address" name="row[address]" autocomplete="off" value=""/>
         </div>
     </div>
+
+    <div class="form-group">
+        <label for="remarks" class="control-label col-xs-12 col-sm-2">{:__('Remarks')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input type="text" class="form-control" id="remarks" name="row[remarks]" autocomplete="off" value="" />
+        </div>
+    </div>
     <div class="form-group hidden layer-footer">
         <label class="control-label col-xs-12 col-sm-2"></label>
         <div class="col-xs-12 col-sm-8">

+ 41 - 9
application/admin/view/user/user/edit.html

@@ -25,19 +25,45 @@
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">{:__('Bind merchants')}:</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-c_user_id" data-rule="required" data-source="user/user_common/user_level?level=1&type=1"
-                   data-field="nickname" data-multiple="true" data-pagination="false"
-                   class="form-control selectpage" name="row[c_user_id]" type="text" value="{$row.c_user_id}">
+            <select id="c-type_remarks" min="0" class="selectpicker" name="row[type_remarks]" value="{$row.type_remarks|htmlentities}">
+                <option value="" >--请选择备注类型--</option>
+                {foreach name="bindRemarksList" item="vo"}
+                <option value="{$key}" {if $key==$row.type_remarks} selected="selected" {/if} >{$vo}</option>
+                {/foreach}
+            </select>
+
+            <select id="c-bind_remarks" min="0" class="selectpicker"  name="row[bind_remarks]" value="{$row.bind_remarks|htmlentities}" >
+                <option value="" >--请选择备注--</option>
+                {foreach name="$row.user_remarks" item="remark"}
+                <option value="{$remark.id}" {if $remark.id==$row.bind_remarks} selected="selected" {/if} >{$remark.value}</option>
+                {/foreach}
+            </select>
+<!--            <input id="c-c_user_id" data-rule="required" data-source="user/user_common/user_level?level=1&type=1"-->
+<!--                   data-field="nickname" data-multiple="true" data-pagination="false"-->
+<!--                   class="form-control selectpage" name="row[c_user_id]" type="text" value="{$row.c_user_id}">-->
         </div>
     </div>
     {/if}
-
-    <div class="form-group">
-        <label for="c-remarks" class="control-label col-xs-12 col-sm-2">{:__('Remarks')}:</label>
-        <div class="col-xs-12 col-sm-8">
-            <input id="c-remarks" class="form-control" name="row[remarks]" type="text" value="{$row.remarks|htmlentities}">
+    {if($row['type']==1)}
+        <div class="form-group">
+            <label for="remarks1" class="control-label col-xs-12 col-sm-2">{:__('Remarks1')}:</label>
+            <div class="col-xs-12 col-sm-8">
+                <input type="text" class="form-control" id="remarks1" name="row[remarks1]" autocomplete="off" value="{$row.remarks1|htmlentities}" />
+            </div>
         </div>
-    </div>
+        <div class="form-group">
+            <label for="remarks2" class="control-label col-xs-12 col-sm-2">{:__('Remarks2')}:</label>
+            <div class="col-xs-12 col-sm-8">
+                <input type="text" class="form-control" id="remarks2" name="row[remarks2]" autocomplete="off" value="{$row.remarks2|htmlentities}" />
+            </div>
+        </div>
+        <div class="form-group">
+            <label for="remarks3" class="control-label col-xs-12 col-sm-2">{:__('Remarks3')}:</label>
+            <div class="col-xs-12 col-sm-8">
+                <input type="text" class="form-control" id="remarks3" name="row[remarks3]" autocomplete="off" value="{$row.remarks3|htmlentities}" />
+            </div>
+        </div>
+    {/if}
     <div class="form-group">
         <label class="control-label col-xs-12 col-sm-2">省市区:</label>
         <div class="col-xs-12 col-sm-8">
@@ -57,6 +83,12 @@
             {:build_radios('row[status]', ['normal'=>__('Normal'), 'hidden'=>__('Hidden')], $row['status'])}
         </div>
     </div>
+    <div class="form-group">
+        <label for="c-remarks" class="control-label col-xs-12 col-sm-2">{:__('Remarks')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-remarks" class="form-control" name="row[remarks]" type="text" value="{$row.remarks|htmlentities}">
+        </div>
+    </div>
     <div class="form-group layer-footer">
         <label class="control-label col-xs-12 col-sm-2"></label>
         <div class="col-xs-12 col-sm-8">

+ 44 - 6
public/assets/js/backend/user/user.js

@@ -124,21 +124,59 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             $(document).on("change", "#c-level", function () {
                 //变更后的回调事件
                 let checkValue = $("#c-level").val();
-                console.log(checkValue);
-
                 if (checkValue == 1) {
                     $("#div_c-c_user_id").addClass("hidden");
-                    //$("#div_c-city").addClass("hidden");
-                    //$("#div_c-address").addClass("hidden");
+                    $("#div_c_remarks").removeClass("hidden");
                 } else {
                     $("#div_c-c_user_id").removeClass("hidden");
-                    // $("#div_c-city").removeClass("hidden");
-                    // $("#div_c-address").removeClass("hidden");
+                    $("#div_c_remarks").addClass("hidden");
                 }
             });
+
+            $(document).on("change", "#c-type_remarks", function () {
+                //变更后的回调事件
+                let checkValue = $("#c-type_remarks").val();
+                Fast.api.ajax({
+                    url: 'user/user_common/remarks_list',
+                    type: 'post',
+                    data: {
+                        type_remarks: checkValue,
+                    }
+                }, function (data, ret) {
+                    var op = '<option value="">--请选择备注--</option>';
+                    for(var i in data.list){
+                        op += '<option value="'+data.list[i]['id']+'">'+data.list[i]['value']+'</option>'
+                    }
+                    $("#c-bind_remarks").html(op);
+                    $("#c-bind_remarks").selectpicker("refresh");
+                }, function (data, ret) {
+                    console.log("type_remarks-error")
+                });
+            });
         },
         edit: function () {
             Controller.api.bindevent();
+
+            $(document).on("change", "#c-type_remarks", function () {
+                //变更后的回调事件
+                let checkValue = $("#c-type_remarks").val();
+                Fast.api.ajax({
+                    url: 'user/user_common/remarks_list',
+                    type: 'post',
+                    data: {
+                        type_remarks: checkValue,
+                    }
+                }, function (data, ret) {
+                    var op = '<option value="">--请选择备注--</option>';
+                    for(var i in data.list){
+                        op += '<option value="'+data.list[i]['id']+'">'+data.list[i]['value']+'</option>'
+                    }
+                    $("#c-bind_remarks").html(op);
+                    $("#c-bind_remarks").selectpicker("refresh");
+                }, function (data, ret) {
+                    console.log("type_remarks-error")
+                });
+            });
         },
         api: {
             bindevent: function () {