diff --git a/.env.debug b/.env.debug
index 946d744..edce43b 100644
--- a/.env.debug
+++ b/.env.debug
@@ -4,4 +4,26 @@ APP_DEBUG = true
DEFAULT_TIMEZONE = Asia/Shanghai
[LANG]
-default_lang = zh-cn
\ No newline at end of file
+default_lang = zh-cn
+
+[DATABASE]
+TYPE = mysql
+HOSTNAME = 192.168.0.106
+DATABASE = nk_lihaink_cn
+PREFIX = cms_
+USERNAME = root
+PASSWORD = 123321a
+HOSTPORT = 3306
+CHARSET = utf8mb4
+DEBUG = true
+
+[DATABASESHOP]
+TYPE = mysql
+HOSTNAME = 47.108.186.87
+HOSTPORT = 3306
+USERNAME = shop_lihaink_com
+PASSWORD = EeYym2PFctFfrMde
+DATABASE = shop_lihaink_com
+PREFIX = eb_
+CHARSET = utf8
+DEBUG = true
\ No newline at end of file
diff --git a/app/admin/controller/merchant/system/MerchantApplyments.php b/app/admin/controller/merchant/system/merchant/MerchantApplyments.php
similarity index 92%
rename from app/admin/controller/merchant/system/MerchantApplyments.php
rename to app/admin/controller/merchant/system/merchant/MerchantApplyments.php
index ba78965..4ee0d93 100644
--- a/app/admin/controller/merchant/system/MerchantApplyments.php
+++ b/app/admin/controller/merchant/system/merchant/MerchantApplyments.php
@@ -6,11 +6,11 @@
*
* @ 商户入驻申请管理
*/
-namespace app\admin\controller\merchant\system;
+namespace app\admin\controller\merchant\system\merchant;
use app\admin\BaseController;
use app\validate\merchant\MerchantApplymentsValidate;
-use app\admin\model\merchant\MerchantApplyments as MerchantApplymentsModel;
+use app\common\model\merchant\system\merchant\MerchantApplyments as MerchantApplymentsModel;
class MerchantApplyments extends BaseController
{
diff --git a/app/admin/controller/merchant/system/merchant/MerchantIntention.php b/app/admin/controller/merchant/system/merchant/MerchantIntention.php
new file mode 100644
index 0000000..66f14dd
--- /dev/null
+++ b/app/admin/controller/merchant/system/merchant/MerchantIntention.php
@@ -0,0 +1,158 @@
+request = $request;
+ $this->intention = $intention;
+ $this->path = [
+ 'index' => 'merchant/system/merchant/intention/lst',
+ 'mark' => 'merchant/system/merchant/intention/mark',
+ 'read' => 'merchant/system/merchant/intention/read',
+ 'add' => 'merchant/system/merchant/intention/add'
+ ];
+ }
+
+ /**
+ * 显示资源列表
+ *
+ * @return \think\Response
+ */
+ public function Index(MerchantCategory $category, MerchantType $type)
+ {
+ // 商户分类
+ $category = $category->select();
+
+ //审核
+ // 店铺类弄
+ $type = $type->select();
+ // search
+
+ View::assign('category',$category);
+ View::assign('type',$type);
+
+ return View($this->path['index']);
+ }
+
+ public function Lst()
+ {
+ $params = get_params();
+ $page = empty($params['page'])? 1 : (int)$params['page'];
+ $limit = empty($params['limit'])? (int)get_config('app . page_size') : (int)$params['limit'];
+
+ $where = get_params(['mer_name', 'status', 'date', 'keyword', 'mer_intention_id', 'category_id', 'type_id']);
+ $data = $this->intention->GetList($where, $page, $limit);
+
+
+ return to_assign(0, '', $data);
+ }
+
+ public function StatusForm()
+ {
+ return View($this->path['index']);
+ }
+
+ public function MarkForm()
+ {
+ $id = get_params('id');
+ View::assign('id', $id);
+
+ return View($this->path['mark']);
+ }
+
+ /**
+ * 显示创建资源表单页.
+ *
+ * @return \think\Response
+ */
+ public function SetMark()
+ {
+ $id = get_params('id');
+ $mark = get_params('mark');
+ if (!$this->intention->getWhereCount($id))
+ return to_assign(1, '数据不存在');
+
+ $rows = $this->intention->Edit($id, ['mark' => $mark]);
+
+ return $rows>0?to_assign(1, '修改成功'):to_assign(0, '修改失败');
+ }
+
+ /**
+ * 保存新建的资源
+ *
+ * @param \think\Request $request
+ * @return \think\Response
+ */
+ public function save(Request $request)
+ {
+ //
+ }
+
+ /**
+ * 显示指定的资源
+ *
+ * @param int $id
+ * @return \think\Response
+ */
+ public function read($id)
+ {
+ //
+ }
+
+ /**
+ * 显示编辑资源表单页.
+ *
+ * @param int $id
+ * @return \think\Response
+ */
+ public function edit($id)
+ {
+ //
+ }
+
+ /**
+ * 保存更新的资源
+ *
+ * @param \think\Request $request
+ * @param int $id
+ * @return \think\Response
+ */
+ public function update(Request $request, $id)
+ {
+ //
+ }
+
+ /**
+ * 删除指定资源
+ *
+ * @param int $id
+ * @return \think\Response
+ */
+ public function delete($id)
+ {
+ //
+
+ }
+}
diff --git a/app/admin/controller/merchant/system/merchant/MerchantMargin.php b/app/admin/controller/merchant/system/merchant/MerchantMargin.php
index 1e1a444..1502840 100644
--- a/app/admin/controller/merchant/system/merchant/MerchantMargin.php
+++ b/app/admin/controller/merchant/system/merchant/MerchantMargin.php
@@ -11,8 +11,12 @@ declare (strict_types = 1);
namespace app\admin\controller\merchant\system\merchant;
use app\admin\BaseController;
-use think\Request;
use app\common\model\merchant\system\serve\ServeOrder as ServeOrderModel;
+use app\common\model\merchant\user\UserBill as UserBillModel;
+use app\common\model\merchant\system\merchant\Merchant as MerchantModel;
+use think\facade\View;
+use think\exception\ValidateException;
+use think\facade\Request;
/**
* 店铺保证金管理类
@@ -43,7 +47,7 @@ class MerchantMargin extends BaseController
*
* @return \think\Response
*/
- public function lst(ServeOrderModel $order)
+ public function Lst(ServeOrderModel $order)
{
$params = get_params();
$page = empty($params['page'])? 1 : (int)$params['page'];
@@ -56,28 +60,70 @@ class MerchantMargin extends BaseController
return to_assign(0,'success', $data['data']=$data['list']);
}
+ /**
+ * 打开保证金扣费记录面
+ *
+ * @param int $id
+ * @return \think\Response
+ */
+ public function GetMarginLstForm($id)
+ {
+ view::assign('id', $id);
+ return View($this->path['read']);
+ }
+
+
/**
* 获取保证金扣费记录 record
+ *
*/
- public function getMarginLst()
+ public function GetMarginLst(UserBillModel $bill)
{
- return View($this->path['read']);
+ $params = get_params();
+ $mer_id = empty($params['id']) ? 0 : $params['id'];
+ $page = empty($params['page'])? 1 : (int)$params['page'];
+ $limit = empty($params['limit'])? (int)get_config('app . page_size') :(int)$params['limit'];
+
+ $where['mer_id'] = (int)$mer_id;
+ $where['category'] = 'mer_margin';
+
+ $data = $bill->GetList($where, $page, $limit);
+
+ return to_assign(0,'请求成功', $data);
}
/**
* 设置扣减保证金表单
*/
- public function setMarginForm()
+ public function setMarginForm(MerchantModel $merchant)
{
- return View($this->path['edit']);
+
+ $mer_id = get_params('id');
+ $data = $merchant->GetMerchantById($mer_id);
+ if (isset($data->is_margin) && $data->is_margin !== 10) {
+ throw new ValidateException('商户无保证金可扣');
+ }
+
+ return View($this->path['edit'], ['data'=>$data]);
}
/**
* 设置扣减保证金
*/
- public function setMargin()
+ public function setMargin(MerchantModel $merchant)
{
- echo 'fail';
+ $data = get_params(['mer_id','number','mer_name','margin','mark']);
+ if (empty($data['mer_name']) || empty($data['mer_id'])) {
+ return to_assign(0,'商户信息不能为空');
+ }
+ $data['title'] = '保证金扣除';
+ $data['type'] = 'mer_margin';//明细类型=保证金扣除
+ if (!empty($data['number']) && $data['number'] < 0)
+ return to_assign(0,'扣除金额不能小于0');
+
+ $data = $merchant->SetMargin($data);
+
+ return to_assign(0,'扣除保证金成功',[]);
}
@@ -92,16 +138,7 @@ class MerchantMargin extends BaseController
//
}
- /**
- * 显示指定的资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function read($id)
- {
- //
- }
+
/**
* 显示编辑资源表单页.
diff --git a/app/admin/controller/merchant/system/merchant/MerchantType.php b/app/admin/controller/merchant/system/merchant/MerchantType.php
index 1a3dff9..c0239c9 100644
--- a/app/admin/controller/merchant/system/merchant/MerchantType.php
+++ b/app/admin/controller/merchant/system/merchant/MerchantType.php
@@ -7,7 +7,6 @@
* @email:q8197264@126.com
* @date :2023年03月3日
*/
-
declare(strict_types=1);
namespace app\admin\controller\merchant\system\merchant;
diff --git a/app/admin/route/merchant.php b/app/admin/route/merchant.php
index 4d331a7..9a13da9 100644
--- a/app/admin/route/merchant.php
+++ b/app/admin/route/merchant.php
@@ -44,6 +44,41 @@ Route::group(function(){
'_auth' => true,
]);
+ //入驻申请列表
+ Route::group('merchant/intention', function () {
+ Route::get('index', '/index')->name('systemMerchantIntentionLst')->option([
+ '_alias' => '列表',
+ ]);
+
+ Route::get('lst', '/lst')->name('systemMerchantIntentionLst')->option([
+ '_alias' => '列表',
+ ]);
+ Route::post('status', '/switchStatus')->name('systemMerchantIntentionStatus')->option([
+ '_alias' => '审核',
+ ]);
+ Route::delete('delete', '/delete')->name('systemMerchantIntentionDelete')->option([
+ '_alias' => '删除',
+ ]);
+ Route::get('markform', '/markform')->name('systemMerchantIntentionMarkForm')->option([
+ '_alias' => '备注',
+ '_auth' => false,
+ '_form' => 'systemMerchantIntentionMark',
+ ]);
+ Route::get('statusform', '/statusForm')->name('systemMerchantIntentionStatusForm')->option([
+ '_alias' => '申请商户',
+ '_auth' => false,
+ '_form' => 'systemMerchantIntentionStatus',
+ ]);
+
+ Route::post('mark', '/setmark')->name('systemMerchantIntentionMark')->option([
+ '_alias' => '备注',
+ ]);
+ Route::get('excel', '/excel');
+ })->prefix('merchant.system.merchant.MerchantIntention')->option([
+ '_path' => '/merchant/application',
+ '_auth' => true,
+ ]);
+
// 店铺类型
Route::group('/merchant/type',function(){
Route::get('index', '/index')->name('systemMerchantTypeLst')->option([
@@ -102,10 +137,14 @@ Route::group(function(){
Route::get('lst', '/lst')->name('systemMerchantMarginLst')->option([
'_alias' => '缴纳记录',
]);
- //扣费记录
- Route::get('read', '/getMarginLst')->name('systemMarginList')->option([
- '_alias' => '扣费记录',
- ]);
+ //扣费记录页
+ Route::get('read', '/GetMarginLstForm')->name('systemMarginList')->option([
+ '_alias' => '扣费记录页',
+ ]);
+ //扣费记录帐单接口
+ Route::get('reductlst', '/GetMarginLst')->name('systemMarginList')->option([
+ '_alias' => '扣费记录',
+ ]);
//扣除保证金
Route::get('form', '/setMarginForm')->name('systemMarginSetForm')->option([
diff --git a/app/admin/view/merchant/system/merchant/intention/lst.html b/app/admin/view/merchant/system/merchant/intention/lst.html
new file mode 100644
index 0000000..25f3cc8
--- /dev/null
+++ b/app/admin/view/merchant/system/merchant/intention/lst.html
@@ -0,0 +1,283 @@
+{extend name="common/base"/}
+
+{block name="body"}
+
+
+
+
+
+
+
+
+
+{/block}
+
+
+{block name="script"}
+
+{/block}
+
\ No newline at end of file
diff --git a/app/admin/view/merchant/system/merchant/intention/mark.html b/app/admin/view/merchant/system/merchant/intention/mark.html
new file mode 100644
index 0000000..960b7dc
--- /dev/null
+++ b/app/admin/view/merchant/system/merchant/intention/mark.html
@@ -0,0 +1,57 @@
+{extend name="common/base"/}
+{block name="style"}
+
+{/block}
+
+{block name="body"}
+
+{/block}
+
+
+
+{block name="script"}
+
+
+{/block}
+
\ No newline at end of file
diff --git a/app/admin/view/merchant/system/merchant/margin/edit.html b/app/admin/view/merchant/system/merchant/margin/edit.html
index 5cc27c6..dc722a9 100644
--- a/app/admin/view/merchant/system/merchant/margin/edit.html
+++ b/app/admin/view/merchant/system/merchant/margin/edit.html
@@ -17,54 +17,50 @@
-
+
@@ -91,41 +87,27 @@
height: 500,
});
-
- // 店铺权限
- layui.use(['tree', 'util'], function(){
- var tree = layui.tree
- ,layer = layui.layer
- ,util = layui.util
- //模拟数据
- ,data = [];
-
-
- //监听提交
- form.on('submit(webform)', function (data) {
- console.log(data.field);
- // data.field.content = tinyMCE.editors['container_content'].getContent();
- if (data.field == '') {
- layer.msg('请先完善店铺类型');
- return false;
- }
- let callback = function (e) {
- layer.msg(e.msg);
- if (e.code == 0) {
- tool.tabRefresh(71);
- tool.sideClose(1000);
- }
+ //监听提交
+ form.on('submit(webform)', function (data) {
+ // console.log(data.field);
+ // data.field.content = tinyMCE.editors['container_content'].getContent();
+ if (data.field == '') {
+ layer.msg('请先完善表单输入');
+ return false;
+ }
+ let callback = function (e) {
+ layer.msg(e.msg);
+ if (e.code == 0) {
+ tool.tabRefresh(71);
+ tool.sideClose(1000);
}
+ }
-
- tool.post('/admin/merchant/type/add', data.field, callback);
+
+ tool.post('/admin/margin/reduct', data.field, callback);
- return true;
- });
-
-
+ return true;
});
-
}
diff --git a/app/admin/view/merchant/system/merchant/margin/list.html b/app/admin/view/merchant/system/merchant/margin/list.html
index 3ef43ca..35d77a9 100644
--- a/app/admin/view/merchant/system/merchant/margin/list.html
+++ b/app/admin/view/merchant/system/merchant/margin/list.html
@@ -247,7 +247,7 @@
elem: '#refund_list',
title: '退回保证金列表',
toolbar: '#refundToolbar',
- url: '/admin/margin/lst',
+ url: '/admin/margin/refund/lst',
page: true,
limit: 20,
cellMinWidth: 300,
@@ -262,7 +262,7 @@
},
{
field: 'mer_name',
- title: '商户名称',
+ title: '商户名称1',
align: 'center',
width: 200,
templet: '{{d.merchant.mer_name}}
'
@@ -299,7 +299,7 @@
fixed: 'right',
field: 'right',
title: '操作',
- toolbar: '#barDemo',
+ toolbar: '#refundBar',
width: 190,
align: 'center'
}
@@ -334,7 +334,9 @@
table.on('tool(refund_list)', function (obj) {
var data = obj.data;
if (obj.event === 'status') {
- tool.side('/admin/margin/read?id=' + obj.data.mer_id);
+ alert("审核");
+ tool.post('/admin/margin/status?id=' + obj.data.mer_id, obj.data);
+
} else if (obj.event === 'mark') {
tool.side('/admin/margin/form?id=' + obj.data.mer_id);
}
@@ -342,6 +344,7 @@
return false;
});
+
//监听搜索提交
// form.on('submit(searchform)', function(data) {
// layui.pageTable.reload({
diff --git a/app/admin/view/merchant/system/merchant/margin/read.html b/app/admin/view/merchant/system/merchant/margin/read.html
index fb1ffb1..1192e1c 100644
--- a/app/admin/view/merchant/system/merchant/margin/read.html
+++ b/app/admin/view/merchant/system/merchant/margin/read.html
@@ -25,6 +25,18 @@
{block name="script"}
{/block}
diff --git a/app/common/model/merchant/system/merchant/Merchant.php b/app/common/model/merchant/system/merchant/Merchant.php
index 309ef66..11d6f3e 100644
--- a/app/common/model/merchant/system/merchant/Merchant.php
+++ b/app/common/model/merchant/system/merchant/Merchant.php
@@ -11,6 +11,8 @@ declare (strict_types = 1);
namespace app\common\model\merchant\system\merchant;
use think\Model;
+use app\common\model\merchant\user\UserBill as UserBillModel;
+use think\exception\ValidateException;
/**
* @mixin \think\Model
@@ -29,4 +31,52 @@ class Merchant extends Model
{
return $this->merchantType()->bind(['type_name']);
}
+
+ /**
+ * 扣除保证金
+ *@param array $data [mer_id] => 75
+ [number] => 2
+ [mer_name] => teert
+ [margin] => 10
+ [mark] => qweqer
+ [title] => 保证金扣除
+ [balance] => 8.00
+ *@return
+ */
+ public function SetMargin($data)
+ {
+ $merchant = $this->GetMerchantById($data['mer_id']);
+
+ if ($merchant->is_margin !== 10) {
+ throw new ValidateException('商户未支付保证金或已申请退款');
+ }
+ if ($data['number'] < 0) {
+ throw new ValidateException('扣除保证金额不能小于0');
+ }
+
+ if (bccomp($merchant->margin, $data['number'], 2) == -1) {
+ throw new ValidateException('扣除保证金额不足');
+ }
+
+ $data['balance'] = bcsub($merchant->margin, $data['number'], 2);
+
+ Merchant::transaction(function () use ($merchant, $data) {
+ $merchant->margin = $data['balance'];
+ $merchant->save();
+ $bill = new UserBillModel();
+ $bill->Bill(0, 'mer_margin', $data['type'], 0, $data);
+ });
+
+ // return [];
+ }
+
+ /**
+ * 查询指定商户信息
+ */
+ public function GetMerchantById($mer_id)
+ {
+ $merchant = Merchant::where('mer_id', $mer_id)->find();
+
+ return $merchant;
+ }
}
diff --git a/app/common/model/merchant/system/merchant/MerchantCategory.php b/app/common/model/merchant/system/merchant/MerchantCategory.php
index 102cace..aece970 100644
--- a/app/common/model/merchant/system/merchant/MerchantCategory.php
+++ b/app/common/model/merchant/system/merchant/MerchantCategory.php
@@ -10,5 +10,6 @@ use think\Model;
*/
class MerchantCategory extends Model
{
- //
+ protected $connection = 'shop';
+ protected $table = 'eb_merchant_category';
}
diff --git a/app/common/model/merchant/system/merchant/MerchantIntention.php b/app/common/model/merchant/system/merchant/MerchantIntention.php
index 061af84..aaba01c 100644
--- a/app/common/model/merchant/system/merchant/MerchantIntention.php
+++ b/app/common/model/merchant/system/merchant/MerchantIntention.php
@@ -1,8 +1,16 @@
hasOne(MerchantCategory::class, 'merchant_category_id', 'merchant_category_id');
+ }
+
+ protected function merchantType()
+ {
+ return $this->hasOne(MerchantType::class, 'mer_type_id', 'mer_type_id');
+ }
+
+
+ /**
+ * 查询入驻申请列表
+ */
+ public function GetList(array $where, $page, $limit)
+ {
+ $query = self::search($where);
+
+ $count = $query->count();
+ $list = $query->page($page, $limit)->order('create_time DESC , status ASC')->with(['merchantCategory', 'merchantType'])->select();
+
+ return compact('count', 'list');
+ }
+
+
+ /**
+ * 查询条件组合
+ * @param array $where 查询条件
+ * @return mixed $query
+ */
+ protected function search(array $where)
+ {
+ $query = self::when(isset($where['mer_id']) && $where['mer_id'] !== '',
+ function ($query) use ($where) {
+ $query->where('mer_id', $where['mer_id']);
+ })
+ ->when(isset($where['uid']) && $where['uid'] !== '',
+ function ($query) use ($where) {
+ $query->where('uid', $where['uid']);
+ })
+ ->when(isset($where['status']) && $where['status'] !== '',
+ function ($query) use ($where) {
+ $query->where('status', (int)$where['status']);
+ })
+ ->when(isset($where['mer_intention_id']) && $where['mer_intention_id'] !== '',
+ function ($query) use ($where) {
+ $query->where('mer_intention_id', $where['mer_intention_id']);
+ })
+ ->when(isset($where['category_id']) && $where['category_id'] !== '',
+ function ($query) use ($where) {
+ $query->where('merchant_category_id', $where['category_id']);
+ })
+ ->when(isset($where['type_id']) && $where['type_id'] !== '',
+ function ($query) use ($where) {
+ $query->where('mer_type_id', $where['type_id']);
+ })
+ ->when(isset($where['keyword']) && $where['keyword'] !== '',
+ function ($query) use ($where) {
+ $query->where('mer_name|phone|mark', 'like', '%' . $where['keyword'] . '%');
+ })
+ ->when(isset($where['date']) && $where['date'] !== '',
+ function ($query) use ($where) {
+ getModelTime($query, $where['date']);
+ }
+ )
+ ->where('is_del', 0);
+
+ return $query;
+ }
+
+ public function Edit($id, $data)
+ {
+ $rows = self::where('mer_intention_id',$id)->update($data);
+ return $rows;
+ }
+
+ public function form($id, $data)
+ {
+ $this->getModel()::getDB()->where($this->getPk(), $id)->update(['status' => $data['status'], 'mark' => $data['mark']]);
+ }
+
+ public function GetWhereCount($mer_intention_id)
+ {
+ $count = self::where(['mer_intention_id' => $mer_intention_id, 'is_del' => 0])->fetchSql()->count();
+
+ return $count;
+ }
}
diff --git a/app/common/model/merchant/system/serve/ServeOrder.php b/app/common/model/merchant/system/serve/ServeOrder.php
index e027f14..c9818b0 100644
--- a/app/common/model/merchant/system/serve/ServeOrder.php
+++ b/app/common/model/merchant/system/serve/ServeOrder.php
@@ -62,28 +62,40 @@ class ServeOrder extends Model
{
$query = self::hasWhere('merchant',function($query) use($where) {
- $query->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use($where){
- $query->whereLike('mer_keyword|real_name|mer_name',"%{$where['keyword']}%");
- });
- $query->when(isset($where['is_trader']) && $where['is_trader'] !== '', function ($query) use($where){
- $query->where('is_trader',$where['is_trader']);
- });
- $query->when(isset($where['category_id']) && $where['category_id'] !== '', function ($query) use($where){
- $query->where('category_id',$where['category_id']);
- });
- $query->when(isset($where['type_id']) && $where['type_id'] !== '', function ($query) use($where){
- $query->where('type_id',$where['type_id']);
- });
+ $query->when(isset($where['keyword']) && $where['keyword'] !== '',
+ function ($query) use($where){
+ $query->whereLike('mer_keyword|real_name|mer_name',"%{$where['keyword']}%");
+ }
+ );
+ $query->when(isset($where['is_trader']) && $where['is_trader'] !== '',
+ function ($query) use($where){
+ $query->where('is_trader',$where['is_trader']);
+ }
+ );
+ $query->when(isset($where['category_id']) && $where['category_id'] !== '',
+ function ($query) use($where){
+ $query->where('category_id',$where['category_id']);
+ }
+ );
+ $query->when(isset($where['type_id']) && $where['type_id'] !== '',
+ function ($query) use($where){
+ $query->where('type_id',$where['type_id']);
+ }
+ );
$query->where('is_del',0);
});
- $query->when(isset($where['type']) && $where['type'] !== '', function ($query) use($where){
- $query->where('ServeOrder.type',$where['type']);
- });
+ $query->when(isset($where['type']) && $where['type'] !== '',
+ function ($query) use($where){
+ $query->where('ServeOrder.type',$where['type']);
+ }
+ );
- $query->when(isset($where['date']) && $where['date'] !== '', function ($query) use($where){
- getModelTime($query,$where['date'],'ServeOrder.create_time');
- });
+ $query->when(isset($where['date']) && $where['date'] !== '',
+ function ($query) use($where){
+ getModelTime($query,$where['date'],'ServeOrder.create_time');
+ }
+ );
$query->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use($where){
$query->where('ServeOrder.mer_id',$where['mer_id']);
diff --git a/app/common/model/merchant/user/UserAddress.php b/app/common/model/merchant/user/UserAddress.php
new file mode 100644
index 0000000..29e8d6b
--- /dev/null
+++ b/app/common/model/merchant/user/UserAddress.php
@@ -0,0 +1,14 @@
+ '佣金转入余额',
+ 'brokerage/order_one' => '获得一级推广佣金',
+ 'brokerage/order_two' => '获得二级推广佣金',
+ 'brokerage/refund_one' => '退还一级佣金',
+ 'brokerage/refund_two' => '退还二级佣金',
+ 'integral/cancel' => '退回积分',
+ 'integral/deduction' => '购买商品',
+ 'integral/lock' => '下单赠送积分',
+ 'integral/refund' => '订单退款',
+ 'integral/refund_lock' => '扣除赠送积分',
+ 'integral/sign_integral' => '签到赠送积分',
+ 'integral/spread' => '邀请好友',
+ 'integral/sys_dec' => '系统减少积分',
+ 'integral/sys_inc' => '系统增加积分',
+ 'integral/timeout' => '积分过期',
+ 'mer_integral/deduction' => '积分抵扣',
+ 'mer_integral/refund' => '订单退款',
+ 'mer_lock_money/order' => '商户佣金冻结',
+ 'now_money/brokerage' => '佣金转入余额',
+ 'now_money/pay_product' => '购买商品',
+ 'now_money/presell' => '支付预售尾款',
+ 'now_money/recharge' => '余额充值',
+ 'now_money/sys_dec_money' => '系统减少余额',
+ 'now_money/sys_inc_money' => '系统增加余额',
+ ];
+
+
+ /**
+ * TODO: 短信通知待开发
+ * 创建用户帐单
+ *
+ * @param int $uid
+ * @param string $category
+ * @param string $type
+ * @param int $pm
+ * @param array $data
+ * @return BaseDao|Model
+ */
+ public function Bill(int $uid, string $category, string $type, int $pm, array $data)
+ {
+ $data['category'] = $category;
+ $data['type'] = $type;
+ $data['uid'] = $uid;
+ $data['pm'] = $pm;
+ $bill = self::create($data);
+ if($category == 'now_money'){
+ // 暂不发短信
+ // Queue::push(SendSmsJob::class,['tempId' => 'USER_BALANCE_CHANGE','id' => $bill->bill_id]);
+ }
+ return $bill;
+ }
+
+
+ // protected function getModel(): string
+ // {
+ // return UserBill::class;
+ // }
+
+ /**
+ * 获取查询用户保证金帐单记录
+ * @param array $where 查询条件
+ * @param int $page 当前页
+ * @param int $limit 每页记录数
+ *
+ * @return array
+ */
+ public function GetList($where, $page, $limit)
+ {
+ $query = self::SearchJoin($where)->order('a.create_time DESC');
+ $count = $query->count();
+ $list = $query->page($page, $limit)->select();
+
+ return compact('count', 'list');
+ }
+
+ /**
+ * @param array $where
+ * @param $data
+ * @return int
+ * @throws \think\db\exception\DbException
+ * @author xaboy
+ * @day 2020/6/22
+ */
+ public function updateBill(array $where, $data)
+ {
+ return UserBill::where($where)->limit(1)->update($data);
+ }
+
+
+ /**
+ * 查询历史佣金记录
+ *
+ * @param $time
+ * @return \think\Collection
+ * @throws \think\db\exception\DataNotFoundException
+ * @throws \think\db\exception\DbException
+ * @throws \think\db\exception\ModelNotFoundException
+ * @author xaboy
+ * @day 2020/6/22
+ */
+ public function getTimeoutBrokerageBill($time)
+ {
+ return UserBill::where('create_time', '<=', $time)->where('category', 'brokerage')
+ ->whereIn('type', ['order_one', 'order_two'])->with('user')->where('status', 0)->select();
+ }
+
+ /**
+ * 查询历史积分记录
+ */
+ public function getTimeoutIntegralBill($time)
+ {
+ return UserBill::where('create_time', '<=', $time)->where('category', 'integral')
+ ->where('type', 'lock')->with('user')->where('status', 0)->select();
+ }
+
+ public function getTimeoutMerchantMoneyBill($time)
+ {
+ return UserBill::where('create_time', '<=', $time)->where('category', 'mer_computed_money')->where('type','order')
+ ->where('status', 0)->select();
+ }
+
+ public function refundMerchantMoney($order_id, $type, $mer_id)
+ {
+ return UserBill::where('link_id', $order_id)->where('mer_id', $mer_id)
+ ->where('category', 'mer_refund_money')->where('type', $type)->sum('number');
+ }
+
+ public function merchantLickMoney($merId = null)
+ {
+ $lst = UserBill::where('category', 'mer_lock_money')->when($merId, function ($query, $val) {
+ $query->where('mer_id', $val);
+ })->where('status', 0)->select()->toArray();
+ $lockMoney = 0;
+ if (count($lst)) {
+ $lockMoney = -1 * UserBill::whereIn('link_id', array_column($lst, 'link_id'))
+ ->where('category', 'mer_refund_money')->sum('number');
+ }
+ foreach ($lst as $bill) {
+ $lockMoney = bcadd($lockMoney, $bill['number'], 2);
+ }
+ $lockMoney = bcadd($lockMoney, UserBill::getDB()
+ ->where('category', 'mer_computed_money')->when($merId, function ($query, $val) {
+ $query->where('mer_id', $val);
+ })->where('status', 0)->where('type', 'order')->sum('number'), 2);
+ return $lockMoney;
+ }
+
+ /**
+ * @param $uid
+ * @return float
+ * @author xaboy
+ * @day 2020/6/22
+ */
+ public function lockBrokerage($uid)
+ {
+ $lst = UserBill::where('category', 'brokerage')
+ ->whereIn('type', ['order_one', 'order_two'])->where('uid', $uid)->where('status', 0)->field('link_id,number')->select()->toArray();
+ $refundPrice = 0;
+ if (count($lst)) {
+ $refundPrice = -1 * UserBill::whereIn('link_id', array_column($lst, 'link_id'))->where('uid', $uid)
+ ->where('category', 'brokerage')->whereIn('type', ['refund_two', 'refund_one'])->sum('number');
+ }
+ foreach ($lst as $bill) {
+ $refundPrice = bcadd($refundPrice, $bill['number'], 2);
+ }
+ return $refundPrice;
+ }
+
+ public function lockIntegral($uid = null, $order_id = null)
+ {
+ $lst = UserBill::where('category', 'integral')
+ ->where('type', 'lock')->when($order_id, function ($query, $order_id) {
+ $query->where('link_id', $order_id);
+ })->when($uid, function ($query, $uid) {
+ $query->where('uid', $uid);
+ })->where('status', 0)->field('link_id,number')->select()->toArray();
+ $lockIntegral = 0;
+ if (count($lst)) {
+ $lockIntegral = -1 * UserBill::whereIn('link_id', array_column($lst, 'link_id'))->where('uid', $uid)
+ ->where('category', 'integral')->where('type', 'refund_lock')->sum('number');
+ }
+ foreach ($lst as $bill) {
+ $lockIntegral = bcadd($lockIntegral, $bill['number'], 0);
+ }
+ return $lockIntegral;
+ }
+
+ public function deductionIntegral($uid)
+ {
+ return UserBill::where('uid', $uid)
+ ->where('category', 'integral')->where('type', 'deduction')->sum('number');
+ }
+
+ public function totalGainIntegral($uid)
+ {
+ return UserBill::where('uid', $uid)
+ ->where('category', 'integral')->where('pm', 1)->whereNotIn('type', ['refund', 'cancel'])->sum('number');
+ }
+
+ /**
+ * @param $uid
+ * @return float
+ * @author xaboy
+ * @day 2020/6/22
+ */
+ public function totalBrokerage($uid)
+ {
+ return bcsub(UserBill::where('category', 'brokerage')
+ ->whereIn('type', ['order_one', 'order_two'])->where('uid', $uid)->sum('number'),
+ UserBill::where('uid', $uid)
+ ->where('category', 'brokerage')->whereIn('type', ['refund_two', 'refund_one'])->sum('number'), 2);
+ }
+
+ /**
+ * @param $uid
+ * @return float
+ * @author xaboy
+ * @day 2020/6/22
+ */
+ public function yesterdayBrokerage($uid)
+ {
+ return getModelTime(UserBill::where('category', 'brokerage')
+ ->whereIn('type', ['order_one', 'order_two'])->where('uid', $uid), 'yesterday')->sum('number');
+ }
+
+ /**
+ * @param array $where
+ * @return \think\db\BaseQuery
+ * @author xaboy
+ * @day 2020/6/22
+ */
+ public function search(array $where)
+ {
+ return UserBill::when(isset($where['now_money']) && in_array($where['now_money'], [0, 1, 2]), function ($query) use ($where) {
+ if ($where['now_money'] == 0)
+ $query->where('category', 'now_money')->whereIn('type', ['pay_product', 'recharge', 'sys_inc_money', 'sys_dec_money', 'brokerage', 'presell', 'refund']);
+ else if ($where['now_money'] == 1)
+ $query->where('category', 'now_money')->whereIn('type', ['pay_product', 'sys_dec_money', 'presell']);
+ else if ($where['now_money'] == 2)
+ $query->where('category', 'now_money')->whereIn('type', ['recharge', 'sys_inc_money', 'brokerage', 'refund']);
+ })
+ ->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
+ $query->where('uid', $where['uid'])->where('mer_id', 0);
+ })
+ ->when(isset($where['pm']) && $where['pm'] !== '', function ($query) use ($where) {
+ $query->where('pm', $where['pm']);
+ })
+ ->when(isset($where['category']) && $where['category'] !== '', function ($query) use ($where) {
+ $query->where('category', $where['category']);
+ })
+ ->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
+ $query->where('status', $where['status']);
+ })
+ ->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
+ getModelTime($query, $where['date'], 'create_time');
+ })
+ ->when(isset($where['day']) && $where['day'] !== '', function ($query) use ($where) {
+ $query->whereDay('create_time', $where['day']);
+ })
+ ->when(isset($where['month']) && $where['month'] !== '', function ($query) use ($where) {
+ $query->whereMonth('create_time', $where['month']);
+ })
+ ->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
+ $data = explode('/', $where['type'], 2);
+ if (count($data) > 1) {
+ $query->where('category', $data[0])->where('type', $data[1]);
+ } else {
+ $query->where('type', $where['type']);
+ }
+ })
+ ->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
+ $query->where('mer_id', $where['mer_id']);
+ })
+ ->when(isset($where['link_id']) && $where['link_id'] !== '', function ($query) use ($where) {
+ $query->where('link_id', $where['link_id']);
+ });
+ }
+
+ public function userNowMoneyIncTotal($uid)
+ {
+ return $this->search(['uid' => $uid, 'now_money' => 2])->sum('number');
+ }
+
+ /**
+ * 查询用户帐单
+ * @param array $where 查询条件
+ * @return Query
+ */
+ public function SearchJoin(array $where)
+ {
+ $query = UserBill::alias('a')->leftJoin('User b', 'a.uid = b.uid')
+ ->field('a.bill_id,a.pm,a.title,a.number,a.balance,a.mark,a.create_time,a.status,b.nickname,a.uid,a.category')
+ ->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
+ $query->where('a.mer_id', $where['mer_id']);
+ })
+ ->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
+ $data = explode('/', $where['type'], 2);
+ if (count($data) > 1) {
+ $query->where('a.category', $data[0])->where('type', $data[1]);
+ } else {
+ $query->where('a.type', $where['type']);
+ }
+ })
+ ->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
+ getModelTime($query, $where['date'], 'a.create_time');
+ })
+ ->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
+ $query->whereLike('a.uid|b.nickname|a.title', "%{$where['keyword']}%");
+ })
+ ->when(isset($where['category']) && $where['category'] !== '', function ($query) use ($where) {
+ $query->where('a.category', $where['category']);
+ })->where('category', '<>', 'sys_brokerage');
+
+ return $query;
+ }
+
+ public function refundBrokerage($order_id, $uid)
+ {
+ return UserBill::where('link_id', $order_id)->where('uid', $uid)
+ ->where('category', 'brokerage')->whereIn('type', ['refund_two', 'refund_one'])->sum('number');
+ }
+
+ public function refundIntegral($order_id, $uid)
+ {
+ return UserBill::where('link_id', $order_id)->where('uid', $uid)
+ ->where('category', 'integral')->where('type', 'refund_lock')->sum('number');
+ }
+
+ public function validIntegral($uid, $start, $end)
+ {
+ $lst = UserBill::where('category', 'integral')
+ ->where('type', 'lock')->whereBetween('create_time', [$start, $end])->where('uid', $uid)->where('status', 1)->field('link_id,number')->select()->toArray();
+ $integral = 0;
+ if (count($lst)) {
+ $integral = -1 * UserBill::whereIn('link_id', array_column($lst, 'link_id'))->where('uid', $uid)
+ ->where('category', 'integral')->where('type', 'refund_lock')->sum('number');
+ }
+ foreach ($lst as $bill) {
+ $integral = bcadd($integral, $bill['number'], 0);
+ }
+ $integral2 = UserBill::where('uid', $uid)->whereBetween('create_time', [$start, $end])
+ ->where('category', 'integral')->where('pm', 1)->whereNotIn('type', ['lock', 'refund'])->sum('number');
+ $integral3 = UserBill::where('uid', $uid)->whereBetween('create_time', [$start, $end])
+ ->where('category', 'integral')->where('type', 'sys_dec')->sum('number');
+ return (int)max(bcsub(bcadd($integral, $integral2, 0), $integral3, 0), 0);
+ }
+}
diff --git a/app/common/model/merchant/user/UserHistory.php b/app/common/model/merchant/user/UserHistory.php
new file mode 100644
index 0000000..6a56744
--- /dev/null
+++ b/app/common/model/merchant/user/UserHistory.php
@@ -0,0 +1,14 @@
+