hrjy 2 tahun lalu
induk
melakukan
af7aed06d5

+ 67 - 0
app/admin/controller/user/Achievement.php

@@ -0,0 +1,67 @@
+<?php
+
+namespace app\admin\controller\user;
+
+use app\admin\controller\AuthController;
+use crmeb\services\{FormBuilder as Form, UtilService as Util, JsonService as Json};
+use crmeb\services\JsonService;
+use think\facade\Route as Url;
+use app\admin\model\user\UserNotice as UserNoticeModel;
+use app\admin\model\user\UserNoticeSee as UserNoticeSeeModel;
+use app\admin\model\wechat\WechatUser as UserModel;
+Use app\admin\model\user\UserApply as model;
+
+/**
+ * 用户通知
+ * Class UserNotice
+ * @package app\admin\controller\user
+ */
+class Achievement extends AuthController
+{
+    /**
+     * 显示资源列表
+     *
+     * @return \think\Response
+     */
+    public function index($type)
+    {
+        return $this->fetch();
+    }
+
+    public function indexs($type)
+    {
+
+        $this->assign('type', $type);
+        return $this->fetch();
+    }
+
+    public function list()
+    {
+        $where = Util::getMore([
+            ['status', ''],
+            ['page', 1],
+            ['limit', 20],
+            ['name', ''],
+            ['type', ''],
+            ['status', ''],
+        ]);
+
+        return Json::successlayui(model::list($where));
+    }
+
+    /**
+     * 删除指定资源
+     *
+     * @param int $id
+     * @return \think\Response
+     */
+    public function delete($id)
+    {
+        if (!model::del($id))
+            return Json::fail(UserNoticeModel::getErrorInfo('删除失败,请稍候再试!'));
+        else
+            return Json::successful('删除成功!');
+    }
+
+
+}

+ 17 - 4
app/admin/controller/user/User.php

@@ -15,7 +15,7 @@ use crmeb\basic\BaseModel;
 use app\models\user\UserLevel as Level;
 use app\admin\model\order\StoreOrder;
 use app\admin\model\wechat\WechatMessage;
-use app\admin\model\store\{StoreVisit, StoreCouponUser};
+use app\admin\model\store\{StoreProduct, StoreVisit, StoreCouponUser};
 use app\admin\model\system\{SystemUserLevel, SystemUserTask};
 use crmeb\services\{FormBuilder as Form, UtilService as Util, JsonService as Json};
 use app\admin\model\user\{User as UserModel, UserBill as UserBillAdmin, UserLevel, UserGroup, UserTaskFinish};
@@ -338,7 +338,8 @@ class User extends AuthController
 
         $f[] = Form::radio('alliance', '老师', $user->getData('alliance'))->options([['value' => 1, 'label' => '是'], ['value' => 0, 'label' => '否']]);
         $f[] = Form::radio('shopkeeper', '店家', $user->getData('shopkeeper'))->options([['value' => 1, 'label' => '是'], ['value' => 0, 'label' => '否']]);
-        $f[] = Form::radio('province', '省盟', $user->getData('province'))->options([['value' => 1, 'label' => '是'], ['value' => 0, 'label' => '否']]);
+        $f[] = Form::radio('provinces', '省盟', $user->getData('provinces'))->options([['value' => 1, 'label' => '是'], ['value' => 0, 'label' => '否']]);
+        $f[] = Form::input('address', '省盟地址', $user->getData('address'));
         $f[] = Form::radio('group', '团长', $user->getData('group'))->options([['value' => 1, 'label' => '是'], ['value' => 0, 'label' => '否']]);
 
         $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('update', array('uid' => $uid)), 5);
@@ -363,8 +364,9 @@ class User extends AuthController
             ['spread_uid', 0],
             ['alliance', 0],
             ['shopkeeper', 0],
-            ['province', 0],
+            ['provinces', 0],
             ['group', 0],
+            ['address', 0],
         ]);
         if (!$uid) return $this->failed('数据不存在');
         $user = UserModel::get($uid);
@@ -432,8 +434,9 @@ class User extends AuthController
         $edit['is_promoter'] = $data['is_promoter'];
         $edit['alliance'] = $data['alliance'];
         $edit['shopkeeper'] = $data['shopkeeper'];
-        $edit['province'] = $data['province'];
+        $edit['provinces'] = $data['provinces'];
         $edit['group'] = $data['group'];
+        $edit['address'] = $data['address'];
         if ($edit) $res3 = UserModel::edit($edit, $uid);
         else $res3 = true;
         if ($res1 && $res2 && $res3 && $res_sp) $res = true;
@@ -814,4 +817,14 @@ class User extends AuthController
     {
         return Json::successful(UserBillAdmin::getOneBalanceChangList(compact('uid', 'page', 'limit')));
     }
+
+    /**
+     * 获取某用户的持有优惠劵
+     */
+    public function getProductList($uid, $page = 1, $limit = 20)
+    {
+        return Json::successful(StoreProduct::getProductList(compact('uid', 'page', 'limit')));
+    }
+
+
 }

+ 2 - 1
app/admin/model/order/StoreOrder.php

@@ -442,7 +442,8 @@ HTML;
         if (!$count) return self::setErrorInfo('订单不存在');
         $count = self::where('id', $id)->where('paid', 0)->count();
         if (!$count) return self::setErrorInfo('订单已支付');
-        $res = self::where('id', $id)->update(['paid' => 1, 'pay_time' => time()]);
+        $order = self::where('id', $id)->find();
+        $res = self::where('id', $id)->update(['paid' => 1, 'pay_time' => time()]) && \app\models\store\StoreOrder::reward($order,2);
         return $res;
     }
 

+ 17 - 0
app/admin/model/store/StoreProduct.php

@@ -730,4 +730,21 @@ class StoreProduct extends BaseModel
     {
         return self::where('id', $id)->value($field);
     }
+
+    /**
+     * 获取用户商品
+     * @param $uid
+     * @return mixed
+     */
+    public static function getProductList($data)
+    {
+        $list = self::alias('a')
+            ->field('a.*,b.number')
+            ->leftJoin('user_product b', 'a.id = b.product_id')
+            ->where('b.uid', $data['uid'])
+            ->page($data['page'],$data['limit'])
+            ->select();
+        return $list;
+    }
+
 }

+ 53 - 0
app/admin/model/user/Achievement.php

@@ -0,0 +1,53 @@
+<?php
+/**
+ *
+ * @author: xaboy<365615158@qq.com>
+ * @day: 2017/12/25
+ */
+
+namespace app\admin\model\user;
+
+use crmeb\basic\BaseModel;
+use crmeb\traits\ModelTrait;
+
+/**
+ * TODO 用户申请
+ * Class UserAddress
+ * @package app\models\user
+ */
+class Achievement extends BaseModel
+{
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'achievement';
+
+    use ModelTrait;
+
+    protected $autoWriteTimestamp = true;
+
+    public static function list($where)
+    {
+        $model = self::field('*')->order('id DESC');
+        if ($where['name'])$model->where('name' , 'like', '%'.$where['name'],'%');
+        $data['count'] = $model->count();
+
+        if ($where['page'] && $where['limit']){
+            $model->page($where['page'], $where['limit']);
+        }else{
+            $model->page(20, 1);
+        }
+        $list = $model->select()->toArray();
+        $data['data'] = $list;
+        return $data;
+
+    }
+
+}

+ 1 - 1
app/admin/view/order/store_order/index.php

@@ -571,7 +571,7 @@
             {field: 'pay_price', title: '实际支付', width: '8%', align: 'center'},
             {field: 'paid', title: '支付状态', templet: '#paid',  align: 'center'},
             {field: 'status', title: '订单状态', templet: '#status',  align: 'center'},
-            {field: 'consignor', title: '发货人', templet: '#consignor', align: 'center'},
+            // {field: 'consignor', title: '发货人', templet: '#consignor', align: 'center'},
             {field: 'purchase', title: '订单类型', templet: '#purchase', align: 'center'},
             {field: 'add_time', title: '下单时间', width: '10%', sort: true, align: 'center'},
             {field: 'right', title: '操作', align: 'center', toolbar: '#act', width: '10%'},

+ 8 - 8
app/admin/view/order/store_order/indexs.php

@@ -264,7 +264,7 @@
                         {{#  }else if(d._status==1){ }}
                         {{# if(d.paid == 0 && d.pay_type == 'offline'){ }}
                         <button class="btn btn-danger btn-xs" type="button" lay-event="order_paid">
-                            <i class="fa fa-calendar"></i> 立即支付
+                            <i class="fa fa-calendar"></i> 支付通过
                         </button>
                         {{# } ;}}
                         <button type="button" class="layui-btn layui-btn-xs" onclick="dropdown(this)">操作 <span
@@ -568,17 +568,17 @@
         return [
             {type: 'checkbox'},
             {field: 'order_id', title: '订单号', sort: true, event: 'order_id', width: '11%', templet: '#order_id'},
-            {field: 'nickname', title: '用户信息', templet: '#userinfo', width: '10%', align: 'center'},
-            {field: 'spread_uid', title: '推荐人信息', templet: '#spread_uid', width: '10%', align: 'center'},
+            {field: 'nickname', title: '用户信息', templet: '#userinfo', width: '8%', align: 'center'},
+            {field: 'spread_uid', title: '推荐人信息', templet: '#spread_uid', width: '8%', align: 'center'},
             {field: 'info', title: '商品信息', templet: "#info", height: 'full-20'},
-            {field: 'screenshot', title: '支付截图', templet: "#screenshot"},
+            {field: 'screenshot', title: '支付截图', templet: "#screenshot",width: '4%',},
             {field: 'pay_price', title: '实际支付', width: '8%', align: 'center'},
             {field: 'paid', title: '支付状态', templet: '#paid',  align: 'center'},
             {field: 'status', title: '订单状态', templet: '#status',  align: 'center'},
-            {field: 'consignor', title: '发货人', templet: '#consignor', align: 'center'},
-            {field: 'purchase', title: '订单类型', templet: '#purchase', align: 'center'},
-            {field: 'add_time', title: '下单时间', width: '10%', sort: true, align: 'center'},
-            {field: 'right', title: '操作', align: 'center', toolbar: '#act', width: '10%'},
+            // {field: 'consignor', title: '发货人', templet: '#consignor', align: 'center'},
+            {field: 'purchase', title: '订单类型', templet: '#purchase',width: '6%',align: 'center'},
+            {field: 'add_time', title: '下单时间', width: '9%', sort: true, align: 'center'},
+            {field: 'right', title: '操作', align: 'center', toolbar: '#act', width: '12%'},
         ];
     });
     layList.tool(function (event, data, obj) {

+ 232 - 0
app/admin/view/user/achievment/index.php

@@ -0,0 +1,232 @@
+{extend name="public/container"}
+{block name="head_top"}
+
+{/block}
+{block name="content"}
+<style>
+    .btn-outline{
+        border:none;
+    }
+    .btn-outline:hover{
+        background-color: #0e9aef;
+        color: #fff;
+    }
+    .layui-form-item .layui-btn {
+        margin-top: 5px;
+        margin-right: 10px;
+    }
+    .layui-btn-primary{
+        margin-right: 10px;
+        margin-left: 0!important;
+    }
+    label{
+        margin-bottom: 0!important;
+        margin-top: 4px;
+    }
+</style>
+<div class="layui-fluid">
+    <div class="layui-row layui-col-space15" id="app">
+        <!--搜索条件-->
+        <div class="layui-col-md12">
+            <div class="layui-card">
+                <div class="layui-card-header">申请列表</div>
+                <div class="layui-card-body">
+                    <div class="layui-carousel layadmin-carousel layadmin-shortcut" lay-anim="" lay-indicator="inside" lay-arrow="none" style="background:none">
+                        <form class="layui-form layui-form-pane" action="">
+                            <div class="layui-form-item">
+
+                                <div class="layui-col-lg12">
+                                    <label class="layui-form-label" style="top: -5.5px;">搜索条件</label>
+                                    <div class="layui-input-inline">
+                                        <input type="text" id="name" name="name" class="layui-input" placeholder="请输入用户名称,UID">
+                                    </div>
+                                    <div class="layui-inline">
+                                        <label class="layui-form-label" style="top: -4.5px">状态</label>
+                                        <div class="layui-input-block">
+                                            <select name="status">
+                                                <option value="">全部</option>
+                                                <option value="1">未通过</option>
+                                                <option value="2">待审核</option>
+                                                <option value="3">通过</option>
+                                            </select>
+                                        </div>
+                                    </div>
+
+                                    <div class="layui-inline">
+                                        <div class="layui-input-inline">
+                                            <button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit="search" lay-filter="search">
+                                                <i class="layui-icon layui-icon-search"></i>搜索</button>
+                                        </div>
+                                    </div>
+                                </div>
+                            </div>
+                        </form>
+                    </div>
+                </div>
+            </div>
+        </div>
+
+        <!-- 中间详细信息-->
+        <div :class="item.col!=undefined ? 'layui-col-sm'+item.col+' '+'layui-col-md'+item.col:'layui-col-sm6 layui-col-md3'"
+             v-for="item in badge" v-cloak="" v-if="item.count > 0">
+        </div>
+        <!--enb-->
+    </div>
+    <!--列表-->
+    <div class="layui-row layui-col-space15">
+        <div class="layui-col-md12">
+            <div class="layui-card">
+                <div class="layui-card-header">场次列表</div>
+                <div class="layui-card-body">
+
+                    <div class="layui-btn-container" id="container-action">
+                        <a class="layui-btn layui-btn-sm" onclick="$eb.createModalFrame(this.innerText,'{:Url('create')}',{h:700,w:1100})">添加众筹</a>
+<!--                        <button class="layui-btn layui-btn-sm" data-type="del_auction">批量删除</button>-->
+                    </div>
+                    <table class="layui-hide" id="List" lay-filter="List"></table>
+
+
+                    <script type="text/html" id="image">
+                        <img style="cursor: pointer" lay-event="open_image" src="{{d.image}}">
+                    </script>
+                    <script type="text/html" id="status">
+                        {{#  if(d.status == 0){ }}
+                        <button type="button" name="suc" class="layui-btn-disabled layui-btn-xs" id="">
+                            待审核
+                        </button>
+                        {{#  } else if(d.status == 1) { }}
+                        <button type="button" name="suc" class="layui-btn-xs layui-btn" id="">
+                            通过
+                        </button>
+                        {{#  } else if(d.status == -1) { }}
+                        <button type="button" name="suc" class="layui-btn-disabled layui-btn-xs" id="">
+                            未通过
+                        </button>
+                        {{#  } }}
+                    </script>
+                    <script type="text/html" id="address">
+                        <div> {{d.province}}-{{d.city}}-{{d.district}}</div>
+                        <div> {{d.detail}}</div>
+                    </script>
+                    <script type="text/html" id="act">
+                        <button type="button" class="layui-btn layui-btn-xs layui-btn-danger" lay-event='tg' id="">
+                            通过
+                        </button>
+                        <button type="button" class="layui-btn layui-btn-xs layui-btn-danger" lay-event='btg' id="">
+                            不通过
+                        </button>
+                        <button type="button" class="layui-btn layui-btn-xs layui-btn-danger" lay-event='delete' id="">
+                            删除
+                        </button>
+
+                    </script>
+                </div>
+            </div>
+        </div>
+    </div>
+    <!--end-->
+</div>
+<script src="{__ADMIN_PATH}js/layuiList.js"></script>
+{/block}
+{block name="script"}
+<script>
+    var type = {$type};
+    layList.form.render();
+    layList.tableList('List', "{:Url('list')}?type="+type, function () {
+        return [
+            {type: 'checkbox'},
+            {field: 'id', title: 'ID', sort: true, event: 'id', width: '5%', templet: '#id'},
+            {field: 'nickname', title: '用户名称',  align: 'center'},
+            {field: 'name', title: '姓名', align: 'center'},
+            {field: 'phone', title: '手机号', align: 'center'},
+            {field: 'address', title: '地址', templet: '#address',align: 'center'},
+            {field: 'status', title: '状态',  templet: '#status',align: 'center'},
+            {field: 'create_time', title: '时间', align: 'center'},
+            {field: 'right', title: '操作', align: 'center', toolbar: '#act',width: '15%'},
+        ];
+    });
+
+    //查询
+    layList.search('search',function(where){
+        layList.reload(where,true);
+    });
+
+    //点击事件绑定
+    layList.tool(function (event,data,obj) {
+        switch (event) {
+            case 'delete':
+                var url=layList.U({c:'user.userApply',a:'delete',q:{id:data.id}});
+                var code = {title:"操作提示",text:"确定将该商品移入回收站吗?",type:'info',confirm:'是的,移入回收站'};
+                $eb.$swal('delete',function(){
+                    $eb.axios.get(url).then(function(res){
+                        if(res.status == 200 && res.data.code == 200) {
+                            $eb.$swal('success',res.data.msg);
+                            obj.del();
+                            location.reload();
+                        }else
+                            return Promise.reject(res.data.msg || '删除失败')
+                    }).catch(function(err){
+                        $eb.$swal('error',err);
+                    });
+                },code)
+                break;
+            case 'tg':
+                var url=layList.U({c:'user.userApply',a:'tg',q:{id:data.id,type:type}});
+                var code = {title:"操作提示",text:"确定通过吗?",type:'info',confirm:'是的,确定'};
+                $eb.$swal('delete',function(){
+                    $eb.axios.get(url).then(function(res){
+                        if(res.status == 200 && res.data.code == 200) {
+                            $eb.$swal('success',res.data.msg);
+                            obj.del();
+                            location.reload();
+                        }else
+                            return Promise.reject(res.data.msg || '失败')
+                    }).catch(function(err){
+                        $eb.$swal('error',err);
+                    });
+                },code)
+                break;
+            case 'btg':
+                var url=layList.U({c:'user.userApply',a:'btg',q:{id:data.id}});
+                var code = {title:"操作提示",text:"确定不通过吗?",type:'info',confirm:'是的,确定'};
+                $eb.$swal('delete',function(){
+                    $eb.axios.get(url).then(function(res){
+                        if(res.status == 200 && res.data.code == 200) {
+                            $eb.$swal('success',res.data.msg);
+                            obj.del();
+                            location.reload();
+                        }else
+                            return Promise.reject(res.data.msg || '失败')
+                    }).catch(function(err){
+                        $eb.$swal('error',err);
+                    });
+                },code)
+                break;
+            case 'open_image':
+                $eb.openImage(data.image);
+                break;
+            case 'edit':
+                location.href = layList.U({a:'edit',q:{id:data.id}});
+                break;
+        }
+    })
+
+
+    //改状态
+    layList.switch('status',function (odj,value) {
+        if(odj.elem.checked==true){
+            layList.baseGet(layList.Url({c:'auction.auction',a:'set_status',p:{status:1,id:value}}),function (res) {
+                layList.msg(res.msg, function () {
+                    layList.reload();
+                });
+            });
+        }else{
+            layList.baseGet(layList.Url({c:'auction.auction',a:'set_status',p:{status:0,id:value}}),function (res) {
+                layList.msg(res.msg, function () {
+                    layList.reload();
+                });
+            });
+        }
+    });
+</script>
+{/block}

+ 15 - 1
app/admin/view/user/user/index.php

@@ -254,6 +254,20 @@
                             {{# } }}
                         </ul>
                     </script>
+                    <script type="text/html" id="sf">
+                        {{# if(d.alliance == 1){ }}
+                        <div>老师</div>
+                        {{# } }}
+                        {{# if(d.shopkeeper == 1){ }}
+                        <div>店家</div>
+                        {{# } }}
+                        {{# if(d.provinces == 1){ }}
+                        <div>省盟</div>
+                        {{# } }}
+                        {{# if(d.group == 1){ }}
+                        <div>团长</div>
+                        {{# } }}
+                    </script>
                 </div>
             </div>
         </div>
@@ -314,7 +328,7 @@
             {field: 'extract_count_price', title: '累计提现',align:'center',width:'6%'},
             {field: 'integral', title: '积分',width:'6%',sort:true,event:'integral',align:'center'},
             {field: 'spread_uid_nickname', title: '推荐人',align:'center'},
-            {field: 'sex', title: '性别',width:'4%',align:'center'},
+            {field: 'sf', title: '身份',templet:'#sf',width:'4%',align:'center'},
             {field: 'data_time', title: '访问日期',align:'center',width:'12%',templet:'#data_time'},
             // {field: 'status', title: '状态',templet:"#checkboxstatus",width:'6%',align:'center'},
             {field: 'user_type', title: '用户类型',width:'6%',align:'center'},

+ 45 - 1
app/admin/view/user/user/see.php

@@ -89,6 +89,7 @@
                             <li>持有优惠劵</li>
                             <li>余额变动记录</li>
                             <li>推广下线明细</li>
+                            <li>持有商品</li>
                         </ul>
                         <div class="layui-tab-content" id="content">
                             <div class="layui-tab-item layui-show">
@@ -269,6 +270,30 @@
                                 </table>
                                 <div ref="spread_page" v-show="count.spread_count > limit" style="text-align: right;"></div>
                             </div>
+                            <div class="layui-tab-item">
+                                <table class="layui-table" v-cloak="">
+                                    <thead>
+                                    <tr>
+                                        <th>商品ID</th>
+                                        <th>商品名称</th>
+                                        <th>商品价格</th>
+                                        <th>商品数量</th>
+                                    </tr>
+                                    </thead>
+                                    <tbody>
+                                    <tr v-for="item in ProductList">
+                                        <td>{{item.id}}</td>
+                                        <td>{{item.store_name}}</td>
+                                        <td>{{item.price}}</td>
+                                        <td>{{item.number}}</td>
+                                    </tr>
+                                    <tr v-show="ProductList.length<=0" style="text-align: center">
+                                        <td colspan="5">暂无数据</td>
+                                    </tr>
+                                    </tbody>
+                                </table>
+                                <div ref="product_page" v-show="count.product_count > limit" style="text-align: right;"></div>
+                            </div>
                             <!--end-->
                         </div>
                     </div>
@@ -293,6 +318,7 @@
                 CouponsList:[],
                 balanceChangList:[],
                 SpreadList:[],
+                ProductList:[],
                 count:count,
                 page:{
                     order_page:1,
@@ -301,6 +327,7 @@
                     copons_page:1,
                     balancechang_page:1,
                     spread_page:1,
+                    product_page:1,
                 },
             },
             watch:{
@@ -321,7 +348,10 @@
                 },
                 'page.spread_page':function () {
                     this.getSpreadList();
-                }
+                },
+                'page.product_page':function () {
+                    this.getProductList();
+                },
             },
             methods:{
                 getSpreadList:function(){
@@ -342,6 +372,9 @@
                 getOneBalanceChangList:function () {
                     this.request('getOneBalanceChangList',this.page.balancechang_page,'balanceChangList');
                 },
+                getProductList:function () {
+                    this.request('getProductList',this.page.product_page,'ProductList');
+                },
                 request:function (action,page,name) {
                     var that=this;
                     layList.baseGet(layList.U({a:action,p:{page:page,limit:this.limit,uid:this.uid}}),function (res) {
@@ -356,6 +389,7 @@
                 this.getOneCouponsList();
                 this.getOneBalanceChangList();
                 this.getSpreadList();
+                this.getProductList();
                 var that=this;
                 layList.laypage.render({
                     elem: that.$refs.page_order
@@ -412,6 +446,16 @@
                         that.page.spread_page=obj.curr;
                     }
                 });
+
+                layList.laypage.render({
+                    elem: that.$refs.product_page
+                    ,count:that.count.product_count
+                    ,limit:that.limit
+                    ,theme: '#1E9FFF',
+                    jump:function(obj){
+                        that.page.product_page=obj.curr;
+                    }
+                });
             }
         });
     });

+ 9 - 3
app/api/controller/order/StoreOrderController.php

@@ -356,13 +356,14 @@ class StoreOrderController
      */
     public function lst(Request $request)
     {
-        list($type, $page, $limit, $search) = UtilService::getMore([
+        list($type, $page, $limit, $search, $purchase) = UtilService::getMore([
             ['type', ''],
             ['page', 0],
             ['limit', ''],
             ['search', ''],
+            ['purchase', ''],
         ], $request, true);
-        return app('json')->successful(StoreOrder::getUserOrderSearchList($request->uid(), $type, $page, $limit, $search));
+        return app('json')->successful(StoreOrder::getUserOrderSearchList($request->uid(), $type, $page, $limit, $search, $purchase));
     }
 
     /**
@@ -569,7 +570,12 @@ class StoreOrderController
      */
     public function data(Request $request)
     {
-        return app('json')->successful(StoreOrder::getOrderData($request->uid()));
+
+        list($purchase) = UtilService::getMore([
+            ['purchase', ''],
+        ], $request, true);
+
+        return app('json')->successful(StoreOrder::getOrderData($request->uid(), $purchase));
     }
 
     /**

+ 150 - 4
app/api/controller/user/UserController.php

@@ -5,6 +5,7 @@ namespace app\api\controller\user;
 use app\admin\model\store\StoreProduct;
 use app\admin\model\store\StoreProductAttrValue;
 use app\admin\model\user\UserApply;
+use app\admin\model\user\UserProduct;
 use app\http\validates\user\AddressValidate;
 use app\models\store\StoreCart;
 use app\models\store\StoreOrderCartInfo;
@@ -650,11 +651,19 @@ class UserController
             if (empty($data['shop_introduce'])) return app('json')->fail('店铺简介为空');
         }
         $res = UserApply::create($data);
-        if ($res) return app('json')->fail('申请成功');
+        if ($res) return app('json')->success('申请成功');
         return app('json')->fail('申请失败');
 
     }
 
+    /**
+     * 用户进货
+     * @param Request $request
+     * @return mixed
+     * @throws DataNotFoundException
+     * @throws DbException
+     * @throws ModelNotFoundException
+     */
     public function purchase(Request $request)
     {
         $data = UtilService::postMore([
@@ -663,7 +672,7 @@ class UserController
         ]);
         Db::startTrans();
         $user_add = UserAddress::where('uid', $request->uid())->find();
-        if ($data['image']) return app('json')->fail('上传支付截图');
+        if (!$data['image']) return app('json')->fail('上传支付截图');
         if (!$user_add) return app('json')->fail('请填写地址', ['address' => 0]);
         $cartIds = [];
         $totalNum = 0;
@@ -715,7 +724,7 @@ class UserController
             'pay_postage' => 0,
             'deduction_price' => 0,
             'paid' => 0,
-            'pay_type' => 'yue',
+            'pay_type' => 'offline',
             'gain_integral' => 0,
             'business_integral' => 0,
             'remark' => '',
@@ -740,9 +749,146 @@ class UserController
             return app('json')->success('提交成功');
         }else{
             Db::rollback();
-            return app('json')->success('提交失败');
+            return app('json')->fail('提交失败');
         }
     }
 
+    /**
+     * 用户发货
+     * @param Request $request
+     * @return mixed
+     * @throws DataNotFoundException
+     * @throws DbException
+     * @throws ModelNotFoundException
+     */
+    public function deliver_goods(Request $request)
+    {
+        $data = UtilService::postMore([
+            ['product_id', []],
+            ['uid']
+        ]);
+
+        Db::startTrans();
+        $user_add = UserAddress::where('uid', $data['uid'])->find();
+        if (!$user_add) return app('json')->fail('发货用户未填写地址', ['address' => 0]);
+        if (!$data['uid']) return app('json')->fail('选择发货用户');
+        $cartIds = [];
+        $totalNum = 0;
+        $gainIntegral = 0;
+        $whiteIntegral = 0;
+        $businessIntegral = 0;
+        $price = 0;
+        foreach ($data['product_id'] as $k => $v){
+            $products = StoreProduct::where('id', $k)->find();
+
+            $user_product = UserProduct::where('uid', $request->uid())->where('product_id', $k)->find();
+            if (!$user_product) return app('json')->fail('没有发货商品');
+            if($user_product['number'] < $v) return app('json')->fail('商品数量不够');
+
+            $productArrtValue = StoreProductAttrValue::where('product_id', $products['id'])->find();
+            $cart_id = StoreCart::create([
+                'uid' => $request->uid(),
+                'type' => 'product',
+                'product_id' => $products['id'],
+                'product_attr_unique' => $productArrtValue['unique'],
+                'cart_num' => $v,
+                'add_time' => time(),
+                'is_new' => 1,
+            ]);
+            $cartGroup = StoreCart::getUserProductCartList($request->uid(), $cart_id['id'], 1);
+            $cartInfo = $cartGroup['valid'];
+            StoreOrderCartInfo::setCartInfo(0, $cartInfo);
+            foreach ($cartInfo as $cart) {
+                $cartIds[] = $cart['id'];
+                $totalNum += $cart['cart_num'];
+                // if ($cart['productInfo']['cate_id'] == 4 and $useIntegral) return self::setErrorInfo('该商品不能抵扣', true);
+                $cartInfoGainIntegral = isset($cart['productInfo']['give_integral']) ? bcmul($cart['cart_num'], $cart['productInfo']['give_integral'], 2) : 0;
+                $whiteInfoGainIntegral = isset($cart['productInfo']['white_integral']) ? bcmul($cart['cart_num'], $cart['productInfo']['white_integral'], 2) : 0;
+                $businessGainIntegral = isset($cart['productInfo']['business_integral']) ? bcmul($cart['cart_num'], $cart['productInfo']['business_integral'], 2) : 0;
+                $gainIntegral = bcadd($gainIntegral, $cartInfoGainIntegral, 2);
+                $whiteIntegral = bcadd($whiteIntegral, $whiteInfoGainIntegral, 2);
+                $businessIntegral = bcadd($businessIntegral, $businessGainIntegral, 2);
+                $price += $cart['productInfo']['price'] * $cart['cart_num'];
+            }
+        }
+        $orderInfo = [
+            'uid' => $data['uid'],
+            'order_id' => StoreOrder::getNewOrderId(),
+            'real_name' => $user_add['real_name'],
+            'user_phone' => $user_add['phone'],
+            'user_address' => $user_add['province'] . ' ' . $user_add['city'] . ' ' . $user_add['district'] . ' ' . $user_add['detail'],
+            'cart_id' => $cartIds,
+            'total_num' => $totalNum,
+            'total_price' => $price,
+            'total_postage' => 0,
+            'coupon_id' => 0,
+            'coupon_price' => 0,
+            'pay_price' => $price,
+            'pay_postage' => 0,
+            'deduction_price' => 0,
+            'paid' => 1,
+            'pay_type' => 'yue',
+            'gain_integral' => 0,
+            'business_integral' => 0,
+            'remark' => '',
+            'mark' => '店家发货',
+            'combination_id' => 0,
+            'pink_id' => 0,
+            'freight_price' => 0,
+            'cumulative' => 0,
+            'pay_time' => time(),
+            'add_time' => time(),
+            'unique' => md5(rand(1, 100000).$request->uid()),
+            'refund_price' => 0,
+            'cost' => $products['cost'],
+            'purchase' => 2,
+            'consignor' => $request->uid(),
+        ];
+        $order = StoreOrder::create($orderInfo);
+
+        $res = StoreOrderCartInfo::where('cart_id', 'in', $cartIds)->update(['oid' => $order['id']]);
+        $res1 = StoreOrderStatus::status($order['id'], 'cache_key_create_order', '订单生成');
+        if ($order and $res and $res1){
+            Db::commit();
+            StoreOrder::reward($order,3);
+            return app('json')->success('发货成功');
+        }else{
+            Db::rollback();
+            return app('json')->fail('发货失败');
+        }
+
+    }
+
+    /**用户拥有商品
+     * @param Request $request
+     * @return mixed
+     */
+    public function user_product(Request $request)
+    {
+        $data = UtilService::getMore([
+            ['page', 0],
+            ['limit', 0],
+            ['name', '']
+        ]);
+        if ($data['name']) {
+            $where[] = ['a.store_name', 'like', '%' . $data['name'] . '%'];
+        } else {
+            $where = [];
+        }
+        $list = StoreProduct::alias('a')
+            ->field('a.*,b.number')
+            ->leftJoin('user_product b', 'a.id = b.product_id')
+            ->where('b.uid', $request->uid())
+            ->where($where)
+            ->where('b.number', '>', 0)
+            ->page($data['page'], $data['limit'])
+            ->select();
+        $count = UserProduct::where('uid', $request->uid())->where('number', '>', 0)->count();
+        $list = count($list) > 0 ? $list->toArray() : [];
+
+        return app('json')->success(compact('list', 'count'));
+
+    }
+
 
 }

+ 63 - 21
app/models/store/StoreOrder.php

@@ -9,6 +9,7 @@ namespace app\models\store;
 
 use app\admin\model\system\ShippingTemplatesFree;
 use app\admin\model\system\ShippingTemplatesRegion;
+use app\admin\model\user\UserProduct;
 use crmeb\basic\BaseModel;
 use think\db\exception\DataNotFoundException;
 use think\db\exception\DbException;
@@ -770,9 +771,7 @@ class StoreOrder extends BaseModel
     {
         $order = self::where('order_id', $orderId)->find();
         $productId = StoreProduct::where('is_upgrade', 1)->column('id');
-        if (count(StoreOrderCartInfo::where('oid', $order['id'])->where('product_id', 'in', $productId)->select()) > 0){
-            self::reward($order, $productId);
-        }
+        self::reward($order, 1);
         $resPink = true;
         $res1 = self::where('order_id', $orderId)->update(['paid' => 1, 'pay_type' => $paytype, 'pay_time' => time(), 'is_del' => 0, 'is_system_del' => 0, 'mark' => '']);//订单改为支付
         if ($order->combination_id && $res1 && !$order->refund_status) $resPink = StorePink::createPink($order);//创建拼团
@@ -787,12 +786,19 @@ class StoreOrder extends BaseModel
     }
 
 
-    public static function reward($order, $productId)
+    public static function reward($order,$type)
     {
-        $list = StoreOrderCartInfo::where('oid', $order['id'])->where('product_id', 'in', $productId)->select()->toArray();
+        $list = StoreOrderCartInfo::where('oid', $order['id'])->select();
         $user = User::where('uid', $order['uid'])->find();
         $user1 = User::where('uid', $user['spread_uid'])->find();
         $user2 = User::where('uid', $user1['spread_uid'])->find();
+        if ($type == 1){
+            $str = '购买';
+        }elseif ($type == 2){
+            $str = '进货';
+        }elseif ($type ==3){
+            $str = '店家购买';
+        }
         foreach ($list as $item){
             $product = StoreProduct::where('id', $item['product_id'])->find();
             $num = $item['cart_info']['cart_num'];
@@ -803,19 +809,40 @@ class StoreOrder extends BaseModel
             if ($user1){
                 User::where('uid', $user['spread_uid'])->inc('brokerage_price', $price1+$price2)->update();
                 $user1['brokerage_price'] += $price1;
-                UserBill::income('直推奖励', $user1['uid'], 'now_money', 'push', $price1, $user['uid'], $user1['brokerage_price'], '直推用户'.$user['uid'].'购买商品数量'.$num);
+                UserBill::income('直推奖励', $user1['uid'], 'now_money', 'push', $price1, $user['uid'], $user1['brokerage_price'], '直推用户'.$user['uid'].','.$str.'商品编号'.$item['product_id'].'数量'.$num);
                 $user1['brokerage_price'] += $price2;
-                UserBill::income('直推销售提成', $user1['uid'], 'now_money', 'sale', $price2, $user['uid'], $user1['brokerage_price'], '直推用户'.$user['uid'].'购买商品数量'.$num);
+                UserBill::income('直推销售提成', $user1['uid'], 'now_money', 'sale', $price2, $user['uid'], $user1['brokerage_price'], '直推用户'.$user['uid'].','.$str.'商品编号'.$item['product_id'].'数量'.$num);
             }
 
             if ($user2){
                 User::where('uid', $user1['spread_uid'])->inc('brokerage_price', $price3+$price4)->update();
                 $user2['brokerage_price'] += $price3;
-                UserBill::income('间推奖励', $user2['uid'], 'now_money', 'jt_push', $price3, $user['uid'], $user2['brokerage_price'], '间推用户'.$user['uid'].'购买商品数量'.$num);
+                UserBill::income('间推奖励', $user2['uid'], 'now_money', 'jt_push', $price3, $user['uid'], $user2['brokerage_price'], '间推用户'.$user['uid'].','.$str.'编号'.$item['product_id'].'数量'.$num);
                 $user2['brokerage_price'] += $price4;
-                UserBill::income('间推销售提成', $user2['uid'], 'now_money', 'zt_sale', $price4, $user['uid'], $user2['brokerage_price'], '间推用户'.$user['uid'].'购买商品数量'.$num);
+                UserBill::income('间推销售提成', $user2['uid'], 'now_money', 'zt_sale', $price4, $user['uid'], $user2['brokerage_price'], '间推用户'.$user['uid'].','.$str.'商品编号'.$item['product_id'].'数量'.$num);
+            }
+            if ($type == 2){
+                $user_product = UserProduct::where('uid', $order['uid'])->where('product_id', $item['product_id'])->find();
+                if (!$user_product){
+                    UserProduct::create([
+                        'uid' => $order['uid'],
+                        'product_id' => $item['product_id'],
+                        'number' => $num
+                    ]);
+                }else{
+                    $user_product['number'] += $num;
+                    $user_product->save();
+                }
+            }
+
+            if ($type == 3){
+                $user_product = UserProduct::where('uid', $order['consignor'])->where('product_id', $item['product_id'])->find();
+                $user_product['number'] -= $num;
+                $user_product->save();
             }
         }
+
+        return true;
     }
 
     /*
@@ -1141,12 +1168,19 @@ class StoreOrder extends BaseModel
      * @throws ModelNotFoundException
      * @throws \think\exception\DbException
      */
-    public static function getUserOrderList($uid, $status = '', $page = 0, $limit = 8)
+    public static function getUserOrderList($uid, $status = '', $page = 0, $limit = 8, $purchase = '')
     {
+        if ($purchase == 1){
+            $where[] = ['purchase', '=', 1];
+        }else{
+            $where[] = ['purchase', '<>', 1];
+        }
         if ($page) $list = self::statusByWhere($status, $uid)->where('is_del', 0)->where('uid', $uid)
+            ->where($where)
             ->field('add_time,seckill_id,bargain_id,combination_id,id,order_id,pay_price,total_num,total_price,pay_postage,total_postage,paid,status,refund_status,pay_type,coupon_price,deduction_price,pink_id,delivery_type,is_del,shipping_type')
             ->order('add_time DESC')->page((int)$page, (int)$limit)->select()->toArray();
         else  $list = self::statusByWhere($status, $uid)->where('is_del', 0)->where('uid', $uid)
+            ->where($where)
             ->field('add_time,seckill_id,bargain_id,combination_id,id,order_id,pay_price,total_num,total_price,pay_postage,total_postage,paid,status,refund_status,pay_type,coupon_price,deduction_price,pink_id,delivery_type,is_del,shipping_type')
             ->order('add_time DESC')->page((int)$page, (int)$limit)->select()->toArray();
         foreach ($list as $k => $order) {
@@ -1305,13 +1339,13 @@ class StoreOrder extends BaseModel
      * @param string $search 订单号
      * @return array
      * */
-    public static function getUserOrderSearchList($uid, $type, $page, $limit, $search)
+    public static function getUserOrderSearchList($uid, $type, $page, $limit, $search, $purchase = '')
     {
         if ($search) {
             $order = self::searchUserOrder($uid, $search) ?: [];
             $list = $order == false ? [] : [$order];
         } else {
-            $list = self::getUserOrderList($uid, $type, $page, $limit);
+            $list = self::getUserOrderList($uid, $type, $page, $limit, $purchase);
         }
         foreach ($list as $k => $order) {
             $list[$k] = self::tidyOrder($order, true);
@@ -1382,24 +1416,32 @@ class StoreOrder extends BaseModel
      * @param $uid
      * @return mixed
      */
-    public static function getOrderData($uid)
+    public static function getOrderData($uid, $purchase = '')
     {
+        if ($purchase == 1){
+            $where[] = ['purchase', '=', 1];
+        }else{
+            $where[] = ['purchase', '<>', 1];
+        }
+
         //订单支付没有退款 数量
-        $data['order_count'] = self::where('is_del', 0)->where('paid', 1)->where('uid', $uid)->where('refund_status', 0)->count();
+        $data['order_count'] = self::where('is_del', 0)->where('paid', 1)->where($where)->where('uid', $uid)->where('refund_status', 0)->count();
         //订单支付没有退款 支付总金额
-        $data['sum_price'] = self::where('is_del', 0)->where('paid', 1)->where('uid', $uid)->where('refund_status', 0)->sum('pay_price');
+        $data['sum_price'] = self::where('is_del', 0)->where('paid', 1)->where($where)->where('uid', $uid)->where('refund_status', 0)->sum('pay_price');
         //订单待支付 数量
-        $data['unpaid_count'] = self::statusByWhere(0, $uid)->where('is_del', 0)->where('uid', $uid)->count();
+        $data['unpaid_count'] = self::statusByWhere(0, $uid)->where('is_del', 0)->where($where)->where('uid', $uid)->count();
         //订单待发货 数量
-        $data['unshipped_count'] = self::statusByWhere(1, $uid)->where('is_del', 0)->where('uid', $uid)->count();
+        $data['unshipped_count'] = self::statusByWhere(1, $uid)->where('is_del', 0)->where($where)->where('uid', $uid)->count();
         //订单待收货 数量
-        $data['received_count'] = self::statusByWhere(2, $uid)->where('is_del', 0)->where('uid', $uid)->count();
+        $data['received_count'] = self::statusByWhere(2, $uid)->where('is_del', 0)->where($where)->where('uid', $uid)->count();
         //订单待评价 数量
-        $data['evaluated_count'] = self::statusByWhere(3, $uid)->where('is_del', 0)->where('uid', $uid)->count();
+        $data['evaluated_count'] = self::statusByWhere(3, $uid)->where('is_del', 0)->where($where)->where('uid', $uid)->count();
         //订单已完成 数量
-        $data['complete_count'] = self::statusByWhere(4, $uid)->where('is_del', 0)->where('uid', $uid)->count();
+        $data['complete_count'] = self::statusByWhere(4, $uid)->where('is_del', 0)->where($where)->where('uid', $uid)->count();
         //订单退款
-        $data['refund_count'] = self::statusByWhere(-1, $uid)->where('is_del', 0)->where('uid', $uid)->count();
+        $data['refund_count'] = self::statusByWhere(-1, $uid)->where('is_del', 0)->where($where)->where('uid', $uid)->count();
+
+
         return $data;
     }
 

+ 2 - 0
route/api/route.php

@@ -169,6 +169,8 @@ Route::group(function () {
     Route::post('user/apply', 'user.UserController/apply')->name('apply');//申请成为店家或者老师
     //进货
     Route::post('user/purchase', 'user.UserController/purchase')->name('purchase');//进货
+    Route::post('user/deliver_goods', 'user.UserController/deliver_goods')->name('deliver_goods');//发货
+    Route::get('user/user_product', 'user.UserController/user_product')->name('user_product');//用户拥有商品
 })->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\http\middleware\AuthTokenMiddleware::class, true);
 //未授权接口
 Route::group(function () {