更新供销代码

This commit is contained in:
mkm 2024-02-20 09:41:10 +08:00
parent cd83ab0ccd
commit 4dc07d7b65
37 changed files with 6301 additions and 9 deletions

View File

@ -0,0 +1,114 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\dao\system\supply;
use app\common\dao\BaseDao;
use app\common\model\system\merchant\FinancialRecord;
class FinancialRecordDao extends BaseDao
{
protected function getModel(): string
{
return FinancialRecord::class;
}
/**
* @return string
* @author xaboy
* @day 2020/6/9
*/
public function getSn()
{
list($msec, $sec) = explode(' ', microtime());
$msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
$orderId = 'jy' . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369));
return $orderId;
}
public function inc(array $data, $merId)
{
$data['mer_id'] = $merId;
$data['financial_pm'] = 1;
$data['financial_record_sn'] = $this->getSn();
return $this->create($data);
}
public function dec(array $data, $merId)
{
$data['mer_id'] = $merId;
$data['financial_pm'] = 0;
$data['financial_record_sn'] = $this->getSn();
return $this->create($data);
}
public function search(array $where)
{
$query = $this->getModel()::getDB()
->when(isset($where['financial_type']) && $where['financial_type'] !== '', function ($query) use ($where) {
$query->whereIn('financial_type', $where['financial_type']);
})
->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
$query->where('mer_id', $where['mer_id']);
})
->when(isset($where['user_info']) && $where['user_info'] !== '', function ($query) use ($where) {
$query->where('user_info', $where['user_info']);
})
->when(isset($where['user_id']) && $where['user_id'] !== '', function ($query) use ($where) {
$query->where('user_id', $where['user_id']);
})
->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
$query->whereLike('order_sn|user_info|financial_record_sn', "%{$where['keyword']}%");
})
->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
getModelTime($query, $where['date'], 'create_time');
})
->when(isset($where['is_mer']) && $where['is_mer'] !== '', function ($query) use ($where) {
if($where['is_mer']){
$query->where('mer_id',$where['is_mer'])->where('type','in',[0,1]);
}else{
$query->where('type','in',[1,2]);
}
});
return $query;
}
/**
* TODO 根据条件和时间查询出相对类型的数量个金额
* @param int $type
* @param array $where
* @param string $date
* @param array $financialType
* @return array
* @author Qinii
* @day 4/14/22
*/
public function getDataByType(int $type, array $where, string $date, array $financialType)
{
if (empty($financialType)) return [0,0];
$query = $this->search($where)->where('financial_type','in',$financialType);
if($type == 1) {
$query->whereDay('create_time',$date);
} else if ($type ==2) {
$query->whereMonth('create_time',$date);
}
$count = $query->group('order_id')->count();
$number = $query->sum('number');
return [$count,$number];
}
}

View File

@ -0,0 +1,218 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\dao\system\supply;
use app\common\dao\BaseDao;
use app\common\model\system\merchant\MerchantAdmin;
use think\db\BaseQuery;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Db;
use think\Model;
/**
* Class SupplyAdminDao
* @package app\common\dao\system\merchant
* @author xaboy
* @day 2020-04-17
*/
class SupplyAdminDao extends BaseDao
{
/**
* @return string
* @author xaboy
* @day 2020-04-16
*/
protected function getModel(): string
{
return MerchantAdmin::class;
}
/**
* @param int $merId
* @param array $where
* @param int|null $level
* @return BaseQuery
* @author xaboy
* @day 2020-04-18
*/
public function search(int $merId, array $where = [], ?int $level = null)
{
$query = MerchantAdmin::getDB()->where('is_del', 0)->where('mer_id', $merId)
->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
getModelTime($query, $where['date']);
});
if (!is_null($level)) $query->where('level', $level);
if (isset($where['keyword']) && $where['keyword'] !== '') {
$query = $query->whereLike('real_name|account', '%' . $where['keyword'] . '%');
}
if (isset($where['status']) && $where['status'] !== '') {
$query = $query->where('status', intval($where['status']));
}
return $query;
}
/**
* @param int $merId
* @return string
* @author xaboy
* @day 2020-04-16
*/
public function merIdByAccount(int $merId): string
{
return MerchantAdmin::getDB()->where('mer_id', $merId)->where('level', 0)->value('account');
}
/**
* @param int $merId
* @return array|Model|null
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020/7/7
*/
public function merIdByAdmin(int $merId)
{
return MerchantAdmin::getDB()->where('mer_id', $merId)->where('level', 0)->find();
}
/**
* @param string $account
* @param int $merId
* @return array|Model|null
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-04-20
*/
public function accountByAdmin(string $account, int $merId)
{
return MerchantAdmin::getInstance()->where('account', $account)
->where('is_del', 0)->where('mer_id', $merId)
->field(['account', 'pwd', 'real_name', 'login_count', 'merchant_admin_id', 'status', 'mer_id'])
->find();
}
/**
* @param string $account
* @return array|Model|null
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-04-20
*/
public function accountByTopAdmin(string $account)
{
return MerchantAdmin::getInstance()->where('account', $account)
->where('is_del', 0)->where('level', 0)
->field(['account', 'pwd', 'real_name', 'login_count', 'merchant_admin_id', 'status', 'mer_id'])
->find();
}
/**
* @param string $account
* @return mixed
* @author xaboy
* @day 2020-04-20
*/
public function accountByMerchantId(string $account)
{
return MerchantAdmin::getInstance()->where('account', $account)->value('mer_id');
}
/**
* @param int $id
* @return array|Model|null
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-04-17
*/
public function get( $id)
{
return MerchantAdmin::getInstance()->where('is_del', 0)->find($id);
}
/**
* @param int $id
* @param int $merId
* @param int|null $level
* @return bool
* @author xaboy
* @day 2020-04-18
*/
public function exists(int $id, int $merId = 0, ?int $level = null)
{
$query = MerchantAdmin::getDB()->where($this->getPk(), $id)->where('is_del', 0);
if ($merId) $query->where('mer_id', $merId);
if (!is_null($level)) $query->where('level', $level);
return $query->count() > 0;
}
/**
* @param int $merId
* @param $field
* @param $value
* @param int|null $except
* @return bool
* @author xaboy
* @day 2020-04-18
*/
public function merFieldExists(int $merId, $field, $value, ?int $except = null): bool
{
$query = MerchantAdmin::getDB()->where($field, $value)->where('mer_id', $merId);
if (!is_null($except)) $query->where($this->getPk(), '<>', $except);
return $query->count() > 0;
}
/**
* @param int $id
* @return bool
* @author xaboy
* @day 2020-04-18
*/
public function topExists(int $id)
{
$query = MerchantAdmin::getDB()->where($this->getPk(), $id)->where('is_del', 0)->where('level', 0);
return $query->count() > 0;
}
/**
* @param int $merId
* @return mixed
* @author xaboy
* @day 2020-04-17
*/
public function merchantIdByTopAdminId(int $merId)
{
return MerchantAdmin::getDB()->where('mer_id', $merId)->where('is_del', 0)->where('level', 0)->value('merchant_admin_id');
}
public function deleteMer($merId)
{
MerchantAdmin::getDB()->where('mer_id', $merId)->update(['account' => Db::raw('CONCAT(`account`,\'$del\')')]);
}
}

View File

@ -0,0 +1,51 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\dao\system\supply;
use app\common\dao\BaseDao;
use app\common\model\system\merchant\MerchantApplyments;
class SupplyAppymentsDao extends BaseDao
{
protected function getModel(): string
{
return MerchantApplyments::class;
}
public function search(array $where)
{
$query = $this->getModel()::getDB()
->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_applyments_id']) && $where['mer_applyments_id'] !== '', function ($query) use ($where) {
$query->where('mer_applyments_id', $where['mer_applyments_id']);
})
->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
getModelTime($query, $where['date']);
})
->where('is_del', 0);
return $query;
}
}

View File

@ -0,0 +1,82 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\dao\system\supply;
use app\common\dao\BaseDao;
use app\common\model\BaseModel;
use app\common\model\system\merchant\MerchantCategory;
use think\db\BaseQuery;
use think\facade\Db;
/**
* Class MerchantCategoryDao
* @package app\common\dao\system\merchant
* @author xaboy
* @day 2020-05-06
*/
class SupplyCategoryDao extends BaseDao
{
/**
* @return BaseModel
* @author xaboy
* @day 2020-03-30
*/
protected function getModel(): string
{
return MerchantCategory::class;
}
/**
* @param array $where
* @return BaseQuery
* @author xaboy
* @day 2020-05-06
*/
public function search(array $where = [])
{
return MerchantCategory::getDB();
}
/**
* @return array
* @author xaboy
* @day 2020-05-06
*/
public function allOptions()
{
$data = MerchantCategory::getDB()->column('category_name', 'merchant_category_id');
$options = [];
foreach ($data as $value => $label) {
$options[] = compact('value', 'label');
}
return $options;
}
public function dateMerchantPriceGroup($date, $limit = 4)
{
return MerchantCategory::getDB()->alias('A')->leftJoin('Merchant B', 'A.merchant_category_id = B.category_id')
->leftJoin('StoreOrder C', 'C.mer_id = B.mer_id')->field(Db::raw('sum(C.pay_price) as pay_price,A.category_name'))
->when($date, function ($query, $date) {
getModelTime($query, $date, 'C.pay_time');
})->group('A.merchant_category_id')->where('pay_price', '>', 0)->order('pay_price DESC')->limit($limit)->select();
}
public function names(array $ids)
{
return MerchantCategory::getDB()->whereIn('merchant_category_id', $ids)->column('category_name');
}
}

View File

@ -0,0 +1,309 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\dao\system\supply;
use app\common\dao\BaseDao;
use app\common\model\system\merchant\Merchant;
use crmeb\services\VicWordService;
use think\db\BaseQuery;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Db;
use think\Model;
class SupplyDao extends BaseDao
{
/**
* @return string
* @author xaboy
* @day 2020-04-16
*/
protected function getModel(): string
{
return Merchant::class;
}
/**
* @param array $where
* @return BaseQuery
* @author xaboy
* @day 2020-04-16
*/
public function search(array $where, $is_del = 0)
{
$query = Merchant::getDB()
->when($is_del !== null, function ($query) use ($is_del) {
$query->where('is_del', $is_del);
})
->when(isset($where['is_trader']) && $where['is_trader'] !== '', function ($query) use ($where) {
$query->where('is_trader', $where['is_trader']);
})
->when(isset($where['is_margin']) && $where['is_margin'] !== '', function ($query) use ($where) {
$query->where('is_margin', $where['is_margin']);
})
//补缴
->when(isset($where['margin']) && $where['margin'] !== '', function ($query) use ($where) {
if ($where['margin']) {
$query->where('is_margin',$where['margin']);
} else {
$query->where(function($query){
$query->where('is_margin',1)->whereOr(function($query){
$query->where('is_margin',10)->whereRaw('ot_margin > margin');
});
});
}
})
->when(isset($where['is_best']) && $where['is_best'] !== '', function ($query) use ($where) {
$query->where('is_best', $where['is_best']);
})
->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
getModelTime($query, $where['date']);
})
->when(isset($where['mer_state']) && $where['mer_state'] !== '', function ($query) use ($where) {
$query->where('mer_state', $where['mer_state']);
})
->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
$query->where('mer_id', $where['mer_id']);
})
->when(isset($where['category_id']) && $where['category_id'] !== '', function ($query) use ($where) {
$query->whereIn('category_id', is_array($where['category_id']) ? $where['category_id'] : explode(',', $where['category_id']));
})
->when(isset($where['type_id']) && $where['type_id'] !== '', function ($query) use ($where) {
$query->whereIn('type_id', is_array($where['type_id']) ? $where['type_id'] : explode(',', $where['type_id']));
})
->when(isset($where['delivery_way']) && $where['delivery_way'] !== '', function ($query) use ($where) {
$query->whereLike('delivery_way', "%{$where['delivery_way']}%");
});
if (isset($where['keyword']) && $where['keyword']) {
if (is_numeric($where['keyword'])) {
$query->whereLike('mer_name|mer_keyword|mer_phone', "%{$where['keyword']}%");
} else {
$word = app()->make(VicWordService::class)->getWord($where['keyword']);
$query->where(function ($query) use ($word, $where) {
foreach ($word as $item) {
if(mb_strlen($item) > 1) {
$query->whereOr('mer_name', 'LIKE', "%$item%");
}
}
$query->whereOr('mer_name|mer_keyword', 'LIKE', "%{$where['keyword']}%");
});
}
}
if (isset($where['status']) && $where['status'] !== '')
$query->where('status', $where['status']);
$order = $where['order'] ?? '';
$query->when($order, function ($query) use ($where, $order) {
if ($order == 'rate') {
$query->order('is_best DESC, product_score DESC,service_score DESC,postage_score DESC, sort DESC');
} else if ($order == 'location' && isset($where['location']['long'], $where['location']['lat'])) {
$lng = (float)$where['location']['long'];
$lat = (float)$where['location']['lat'];
$query->whereNotNull('lat')->whereNotNull('long')
->order(Db::raw("(2 * 6378.137 * ASIN(
SQRT(
POW( SIN( PI( ) * ( $lng- `long` ) / 360 ), 2 ) + COS( PI( ) * $lat / 180 ) * COS( `lat` * PI( ) / 180 ) * POW( SIN( PI( ) * ( $lat- `lat` ) / 360 ), 2 )
)
)
) ASC "));
} else {
$query->order('sort DESC,create_time DESC');
}
}, function ($query) use ($order) {
$query->order('is_best DESC, sort DESC,sales DESC');
});
return $query;
}
/**
* @param int $id
* @return array|Model|null
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-04-17
*/
public function get($id)
{
return Merchant::getInstance()->where('is_del', 0)->find($id);
}
/**
* @param $id
* @author Qinii
*/
public function apiGetOne($id)
{
return Merchant::getInstance()->where(['is_del' => 0, 'status' => 1, 'mer_state' => 1])->find($id);
}
/**
* @param int $merId
* @author Qinii
*/
public function incCareCount(int $merId)
{
($this->getModel()::getDB())->where($this->getPk(), $merId)->inc('care_count', 1)->update();
}
/**
* @param int $merId
* @param int $inc
* @author xaboy
* @day 2020/9/25
*/
public function incSales($merId, $inc)
{
($this->getModel()::getDB())->where($this->getPk(), $merId)->inc('sales', $inc)->update();
}
/**
* @param int $merId
* @author Qinii
*/
public function decCareCount(array $merId)
{
($this->getModel()::getDB())->whereIn($this->getPk(), $merId)->where('care_count', '>', 0)->dec('care_count', 1)->update();
}
public function dateMerchantNum($date)
{
return Merchant::getDB()->where('is_del', 0)->when($date, function ($query, $date) {
getModelTime($query, $date);
})->count();
}
/**
* TODO 获取复制商品次数
* @param int $merId
* @return mixed
* @author Qinii
* @day 2020-08-06
*/
public function getCopyNum(int $merId)
{
return Merchant::getDB()->where('mer_id', $merId)->value('copy_product_num');
}
/**
* TODO 变更复制次数
* @param int $merId
* @param int $num 正负数
* @return mixed
* @author Qinii
* @day 2020-08-06
*/
public function changeCopyNum(int $merId, int $num)
{
return $this->getModel()::where('mer_id', $merId)->inc('copy_product_num', $num)->update();
}
/**
* @param $field
* @param $value
* @param int|null $except
* @return bool
* @author xaboy
* @day 2020-03-30
*/
public function fieldExists($field, $value, ?int $except = null): bool
{
$query = ($this->getModel())::getDB()->where($field, $value);
if (!is_null($except)) $query->where($this->getPk(), '<>', $except);
return $query->where('is_del', 0)->count() > 0;
}
public function names(array $ids)
{
return Merchant::getDB()->whereIn('mer_id',$ids)->column('mer_name');
}
/**
* TODO 增加商户余额
* @param int $merId
* @param float $num
* @author Qinii
* @day 3/19/21
*/
public function addMoney(int $merId, float $num)
{
$field = 'mer_money';
$merchant = $this->getModel()::getDB()->where('mer_id', $merId)->find();
if ($merchant) {
$mer_money = bcadd($merchant[$field], $num, 2);
$merchant[$field] = $mer_money;
$merchant->save();
}
}
/**
* TODO 减少商户余额
* @param int $merId
* @param float $num
* @author Qinii
* @day 3/19/21
*/
public function subMoney(int $merId, float $num)
{
$field = 'mer_money';
$merchant = $this->getModel()::getDB()->where('mer_id', $merId)->find();
if ($merchant) {
$mer_money = bcsub($merchant[$field], $num, 2);
$merchant[$field] = $mer_money;
$merchant->save();
}
}
public function clearTypeId(int $typeId)
{
return Merchant::getDB()->where('type_id', $typeId)->update(['type_id' => 0]);
}
public function addFieldNum(int $merId, int $num, string $field)
{
if ($num < 0) $num = -$num;
$merchant = $this->getModel()::getDB()->where('mer_id', $merId)->find();
$number = $merchant[$field] + $num;
$merchant[$field] = $number;
$merchant->save();
}
public function sumFieldNum(int $merId, int $num, string $field)
{
if ($num < 0) $num = -$num;
$merchant = $this->getModel()::getDB()->where('mer_id', $merId)->find();
$number = $merchant[$field] - $num;
$merchant[$field] = $number;
$merchant->save();
}
public function merIdByImage($merIds)
{
return $this->getModel()::getDB()->whereIn('mer_id', $merIds)->column('mer_id,mer_avatar');
}
public function updateMargin($typeId, $margin, $is_margin)
{
return $this->getModel()::where('type_id',$typeId)->where('is_margin','in',[0,1])->update([
'is_margin' => $is_margin,
'margin' => $margin
]);
}
}

View File

@ -0,0 +1,53 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\dao\system\supply;
use app\common\dao\BaseDao;
use app\common\model\system\merchant\MerchantIntention;
class SupplyIntentionDao extends BaseDao
{
protected function getModel(): string
{
return MerchantIntention::class;
}
public function search(array $where)
{
$query = $this->getModel()::getDB()->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 form($id, $data)
{
$this->getModel()::getDB()->where($this->getPk(), $id)->update(['status' => $data['status'], 'mark' => $data['mark']]);
}
}

View File

@ -0,0 +1,72 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\dao\system\supply;
use app\common\dao\BaseDao;
use app\common\model\BaseModel;
use app\common\model\system\merchant\MerchantType;
class SupplyTypeDao extends BaseDao
{
protected function getModel(): string
{
return MerchantType::class;
}
public function search(array $where = [])
{
return MerchantType::getDB()
->when(isset($where['mer_type_id']) && $where['mer_type_id'] !== '',function($query) use($where){
$query->where('mer_type_id',$where['mer_type_id']);
});
}
public function getOptions()
{
$data = MerchantType::getDB()->column('type_name', 'mer_type_id');
$options = [];
foreach ($data as $value => $label) {
$options[] = compact('value', 'label');
}
return $options;
}
public function getMargin()
{
$data = MerchantType::getDB()->column('margin,is_margin', 'mer_type_id');
$options = [];
foreach ($data as $value => $item) {
if ($item['is_margin'] == 1) {
$options[] = [
'value' => $value,
'rule' => [
[
'type' => 'div',
'children' => [
'保证金:' . $item['margin']. ' 元'
],
'style' => [
'paddingTop' => '100px',
],
]
]
];
}
}
return $options;
}
}

View File

@ -0,0 +1,60 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\model\system\supply;
use app\common\model\BaseModel;
use app\common\model\store\order\StoreOrder;
use app\common\model\store\order\StoreRefundOrder;
use app\common\model\user\User;
use app\common\model\user\UserOrder;
class FinancialRecord extends BaseModel
{
public static function tablePk(): ?string
{
return 'financial_record_id';
}
public static function tableName(): string
{
return 'financial_record';
}
public function user()
{
return $this->hasOne(User::class, 'uid', 'user_id');
}
public function merchant()
{
return $this->hasOne(Supply::class, 'mer_id', 'mer_id');
}
public function orderInfo()
{
return $this->hasOne(StoreOrder::class, 'order_sn', 'order_sn');
}
public function refundOrder()
{
return $this->hasOne(StoreRefundOrder::class, 'refund_order_sn', 'order_sn');
}
public function userOrder()
{
return $this->hasOne(UserOrder::class, 'order_sn', 'order_sn');
}
}

View File

@ -0,0 +1,273 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\model\system\supply;
use app\common\dao\store\product\ProductDao;
use app\common\model\BaseModel;
use app\common\model\store\coupon\StoreCouponUser;
use app\common\model\store\product\Product;
use app\common\model\store\product\Spu;
use app\common\model\store\service\StoreService;
use app\common\model\system\config\SystemConfigValue;
use app\common\model\system\financial\Financial;
use app\common\model\system\serve\ServeOrder;
use app\common\repositories\store\StoreActivityRepository;
class Supply extends BaseModel
{
/**
* @return string
* @author xaboy
* @day 2020-03-30
*/
public static function tablePk(): string
{
return 'mer_id';
}
/**
* @return string
* @author xaboy
* @day 2020-03-30
*/
public static function tableName(): string
{
return 'supply';
}
public function getDeliveryWayAttr($value)
{
if (!$value) return [];
return explode(',',$value);
}
public function product()
{
return $this->hasMany(Product::class, 'mer_id', 'mer_id');
}
public function config()
{
return $this->hasMany(SystemConfigValue::class, 'mer_id', 'mer_id');
}
public function showProduct()
{
return $this->hasMany(Product::class, 'mer_id', 'mer_id')
->where((new ProductDao())->productShow())
->field('mer_id,product_id,store_name,image,price,is_show,status,is_gift_bag,is_good')
->order('is_good DESC,sort DESC');
}
/**
* TODO 商户列表下的推荐
* @return \think\Collection
* @author Qinii
* @day 4/20/22
*/
public function getAllRecommendAttr()
{
$list = Product::where('mer_id', $this['mer_id'])
->where((new ProductDao())->productShow())
->field('mer_id,product_id,store_name,image,price,is_show,status,is_gift_bag,is_good,cate_id')
->order('is_good DESC, sort DESC, create_time DESC')
->limit(3)
->select()->append(['show_svip_info']);
if ($list) {
$data = [];
$make = app()->make(StoreActivityRepository::class);
foreach ($list as $item) {
$spu = Spu::where('product_id',$item->product_id)->where('product_type' ,0)->find();
$spu_id = $spu->spu_id;
$act = $make->getActivityBySpu(StoreActivityRepository::ACTIVITY_TYPE_BORDER,$spu_id,$item['cate_id'],$item['mer_id'],$spu->sys_labels);
$item['border_pic'] = $act['pic'] ?? '';
$data[] = $item;
}
return $data;
}
return [];
}
public function getCityRecommendAttr()
{
$list = Product::where('mer_id', $this['mer_id'])
->where((new ProductDao())->productShow())
->whereLike('delivery_way',"%1%")
->field('mer_id,product_id,store_name,image,price,is_show,status,is_gift_bag,is_good,cate_id')
->order('sort DESC, create_time DESC')
->limit(3)
->select();
if ($list) {
$data = [];
$make = app()->make(StoreActivityRepository::class);
foreach ($list as $item) {
$spu = Spu::where('product_id',$item->product_id)->where('product_type' ,0)->find();
$spu_id = $spu->spu_id;
$act = $make->getActivityBySpu(StoreActivityRepository::ACTIVITY_TYPE_BORDER,$spu_id,$item['cate_id'],$item['mer_id'],$spu->sys_labels);
$item['border_pic'] = $act['pic'] ?? '';
$data[] = $item;
}
return $data;
}
return [];
}
public function recommend()
{
return $this->hasMany(Product::class, 'mer_id', 'mer_id')
->where((new ProductDao())->productShow())
->where('is_good', 1)
->field('mer_id,product_id,store_name,image,price,is_show,status,is_gift_bag,is_good,sales,create_time')
->order('is_good DESC,sort DESC,create_time DESC')
->limit(3);
}
public function coupon()
{
$time = date('Y-m-d H:i:s');
return $this->hasMany(StoreCouponUser::class, 'mer_id', 'mer_id')->where('start_time', '<', $time)->where('end_time', '>', $time)
->where('is_fail', 0)->where('status', 0)->order('coupon_price DESC, coupon_user_id ASC')
->with(['product' => function ($query) {
$query->field('coupon_id,product_id');
}, 'coupon' => function ($query) {
$query->field('coupon_id,type');
}]);
}
public function getServicesTypeAttr()
{
//0 支持在线聊天 1 支持电话 -1 暂无客服
$services_type = merchantConfig($this->mer_id,'services_type');
if ($services_type) {
if (!$this->service_phone) $services_type = -1;
} else {
$services_type = 0;
$where = ['mer_id' => $this->mer_id, 'is_open' => 1,'status' => 1];
$service = StoreService::where($where)->count();
if (!$service) $services_type = -1;
}
return $services_type;
}
public function marginOrder()
{
return $this->hasMany(ServeOrder::class, 'mer_id','mer_id')->where('type', 10)->order('create_time DESC');
}
public function refundMarginOrder()
{
return $this->hasOne(Financial::class, 'mer_id', 'mer_id')
->where('type',1)
->where('status', -1)
->order('create_time DESC')
->limit(1);
}
public function merchantCategory()
{
return $this->hasOne(SupplyCategory::class, 'merchant_category_id', 'category_id');
}
public function merchantType()
{
return $this->hasOne(SupplyType::class, 'mer_type_id', 'type_id');
}
public function typeName()
{
return $this->merchantType()->bind(['type_name']);
}
public function categoryName()
{
return $this->merchantCategory()->bind(['category_name']);
}
public function getMerCommissionRateAttr()
{
return $this->commission_swtich ? $this->commission_rate : $this->merchantCategory->commission_rate;
}
public function getOpenReceiptAttr()
{
return merchantConfig($this->mer_id, 'mer_open_receipt');
}
public function admin()
{
return $this->hasOne(SupplyAdmin::class, 'mer_id', 'mer_id')->where('level', 0);
}
public function searchKeywordAttr($query, $value)
{
$query->whereLike('mer_name|mer_keyword', "%{$value}%");
}
public function getFinancialAlipayAttr($value)
{
return $value ? json_decode($value) : $value;
}
public function getFinancialWechatAttr($value)
{
return $value ? json_decode($value) : $value;
}
public function getFinancialBankAttr($value)
{
return $value ? json_decode($value) : $value;
}
public function getMerCertificateAttr()
{
return merchantConfig($this->mer_id, 'mer_certificate');
}
public function getIssetCertificateAttr()
{
return count(merchantConfig($this->mer_id, 'mer_certificate') ?: []) > 0;
}
public function getMarginRemindStatusAttr()
{
if (systemConfig('margin_remind_switch') == '1' && $this->mer_state) {
if ($this->is_margin == 10) {
if($this->ot_margin > $this->margin) {
if (!$this->margin_remind_time) {
$day = systemConfig('margin_remind_day') ?: 0;
if($day) {
$time = strtotime(date('Y-m-d 23:59:59',strtotime("+ $day day",time())));
$this->margin_remind_time = $time;
} else {
$this->status = 0;
$this->mer_state = 0;
}
$this->save();
}
return $this->margin_remind_time;
}
}
}
return null;
}
public function searchMerIdsAttr($query, $value)
{
$query->whereIn('mer_id',$value);
}
}

View File

@ -0,0 +1,76 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\model\system\supply;
use app\common\model\BaseModel;
use app\common\model\system\auth\Role;
class SupplyAdmin extends BaseModel
{
/**
* @return string
* @author xaboy
* @day 2020-03-30
*/
public static function tablePk(): string
{
return 'merchant_admin_id';
}
/**
* @return string
* @author xaboy
* @day 2020-03-30
*/
public static function tableName(): string
{
return 'merchant_admin';
}
/**
* @param $value
* @return array
* @author xaboy
* @day 2020-03-30
*/
public function getRolesAttr($value)
{
return array_map('intval', explode(',', $value));
}
/**
* @param $value
* @return string
* @author xaboy
* @day 2020-03-30
*/
public function setRolesAttr($value)
{
return implode(',', $value);
}
/**
* @param bool $isArray
* @return array|string
* @author xaboy
* @day 2020-04-18
*/
public function roleNames($isArray = false)
{
$roleNames = Role::getDB()->whereIn('role_id', $this->roles)->column('role_name');
return $isArray ? $roleNames : implode(',', $roleNames);
}
}

View File

@ -0,0 +1,80 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\model\system\supply;
use app\common\model\BaseModel;
class SupplyApplyments extends BaseModel
{
/**
* TODO
* @return string
* @author Qinii
* @day 6/22/21
*/
public static function tablePk(): string
{
return 'mer_applyments_id';
}
/**
* TODO
* @return string
* @author Qinii
* @day 6/22/21
*/
public static function tableName(): string
{
return 'merchant_applyments';
}
public function merchant()
{
return $this->hasOne(Supply::class,'mer_id','mer_id');
}
public function searchOutRequestNoAttr($query,$value)
{
$query->where('out_request_no',$value);
}
public function searchKeywordAttr($query,$value)
{
$query->whereLike('mer_name',"%{$value}%");
}
public function searchMerIdAttr($query,$value)
{
$query->where('mer_id',$value);
}
public function searchStatusAttr($query,$value)
{
$query->where('status',$value);
}
public function searchDateAttr($query,$value)
{
getModelTime($query,$value);
}
public function searchMerApplymentsIdAttr($query,$value)
{
$query->where('mer_applyments_id',$value);
}
public function searchIsDelAttr($query,$value)
{
$query->where('is_del',$value);
}
}

View File

@ -0,0 +1,47 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\model\system\supply;
use app\common\model\BaseModel;
/**
* Class MerchantCategory
* @package app\common\model\system\merchant
* @author xaboy
* @day 2020-05-06
*/
class SupplyCategory extends BaseModel
{
/**
* @return string
* @author xaboy
* @day 2020-03-30
*/
public static function tablePk(): string
{
return 'merchant_category_id';
}
/**
* @return string
* @author xaboy
* @day 2020-03-30
*/
public static function tableName(): string
{
return 'merchant_category';
}
}

View File

@ -0,0 +1,58 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\model\system\supply;
use app\common\model\BaseModel;
class SupplyIntention extends BaseModel
{
/**
* @return string
* @author xaboy
* @day 2020-03-30
*/
public static function tablePk(): string
{
return 'mer_intention_id';
}
/**
* @return string
* @author xaboy
* @day 2020-03-30
*/
public static function tableName(): string
{
return 'merchant_intention';
}
public function setImagesAttr($value)
{
return implode(',', $value);
}
public function getImagesAttr($value)
{
return $value ? explode(',', $value) : [];
}
public function merchantCategory()
{
return $this->hasOne(SupplyCategory::class, 'merchant_category_id', 'merchant_category_id')->bind(['category_name']);
}
public function merchantType()
{
return $this->hasOne(SupplyType::class, 'mer_type_id', 'mer_type_id')->bind(['type_name']);
}
}

View File

@ -0,0 +1,41 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\model\system\supply;
use app\common\model\BaseModel;
use app\common\model\system\Relevance;
use app\common\repositories\system\RelevanceRepository;
class SupplyType extends BaseModel
{
public static function tablePk(): ?string
{
return 'mer_type_id';
}
public static function tableName(): string
{
return 'merchant_type';
}
public function auth()
{
return $this->hasMany(Relevance::class, 'left_id', 'mer_type_id')->where('type', RelevanceRepository::TYPE_MERCHANT_AUTH);
}
public function getMerchantCountAttr()
{
return Supply::where('type_id',$this->mer_type_id)->where('status',1)->count();
}
}

View File

@ -0,0 +1,679 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\repositories\system\supply;
use app\common\dao\system\supply\FinancialRecordDao;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\user\UserBillRepository;
use app\common\repositories\user\UserRechargeRepository;
use think\facade\Cache;
use think\facade\Db;
/**
* Class FinancialRecordRepository
* @package app\common\repositories\system\supply
* @author xaboy
* @day 2020/8/5
* @mixin FinancialRecordDao
*/
class FinancialRecordRepository extends BaseRepository
{
const FINANCIA_TYPE_SVIP = 'svip';
public function __construct(FinancialRecordDao $dao)
{
$this->dao = $dao;
}
/**
* TODO 列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @author Qinii
* @day 5/7/21
*/
public function getList(array $where,int $page,int $limit)
{
$query = $this->dao->search($where)->order('create_time DESC');
$count = $query->count();
$list = $query->page($page, $limit)->select();
return compact('count', 'list');
}
/**
* TODO 流水头部计算
* @param int|null $merId
* @param array $where
* @return array
* @author Qinii
* @day 5/7/21
*/
public function getFiniancialTitle(?int $merId,array $where)
{
/**
* 平台支出
* 商户的收入 order_true + 佣金 brokerage_one,brokerage_two + 手续费 refund_charge + 商户预售收入 presell_true
*
* 商户支出
* 退回收入 refund_order + (佣金 brokerage_one,brokerage_two - 退回佣金 refund_brokerage_two,refund_brokerage_one + (手续费 order_charge + 预售手续费 presell_charge - 平台退给商户的手续费 refund_charge
*/
$where['is_mer'] = $merId;
if($merId){
//商户收入
$income = $this->dao->search($where)->where('financial_type','in',['order','mer_presell'])->sum('number');
//商户支出
$expend_ = $this->dao->search($where)->where('financial_type','in',['refund_order','brokerage_one','brokerage_two','order_charge','presell_charge'])->sum('number');
$_expend = $this->dao->search($where)->where('financial_type','in',['refund_charge','refund_brokerage_two','refund_brokerage_one'])->sum('number');
$expend = bcsub($expend_,$_expend,2);
$msg = '商户';
}else{
//平台收入
$income = $this->dao->search($where)->where('financial_type','in',['order','order_presell','presell'])->sum('number');
//平台支出
$expend = $this->dao->search($where)->where('financial_type','in',['brokerage_one','brokerage_two','order_true','refund_charge','presell_true','order_platform_coupon','order_svip_coupon'])->sum('number');
$msg = '平台';
}
$data = [
[
'className' => 'el-icon-s-goods',
'count' => $income,
'field' => '元',
'name' => $msg.'收入'
],
[
'className' => 'el-icon-s-order',
'count' => $expend,
'field' => '元',
'name' => $msg.'支出'
],
];
return $data;
}
/**
* TODO 平台头部统计
* @param $where
* @return array
* @author Qinii
* @day 3/23/21
*/
public function getAdminTitle($where)
{
//订单收入总金额
$count = $this->dao->search($where)->where('financial_type','in',['order','order_presell','presell'])->sum('number');
//退款支出金额
$refund_order = $this->dao->search($where)->where('financial_type','refund_order')->sum('number');
//佣金支出金额
$brokerage_ = $this->dao->search($where)->where('financial_type','in',['brokerage_one','brokerage_two'])->sum('number');
$_brokerage = $this->dao->search($where)->where('financial_type','in',['refund_brokerage_two','refund_brokerage_one'])->sum('number');
$brokerage = bcsub($brokerage_,$_brokerage,2);
//平台手续费
$charge_ = $this->dao->search($where)->where('financial_type','in',['order_charge','presell_charge'])->sum('number');
$_charge = $this->dao->search($where)->where('financial_type','refund_charge')->sum('number');
$charge = bcsub($charge_,$_charge,2);
//优惠券费用 ,'order_platform_coupon','order_svip_coupon'
$coupon = $this->dao->search($where)->where('financial_type','in',['order_platform_coupon','order_svip_coupon'])->sum('number');
$_coupon = $this->dao->search($where)->where('financial_type','in',['refund_platform_coupon','refund_svip_coupon'])->sum('number');
$coupon = bcsub($coupon,$_coupon,2);
//充值金额
$bill_where = [
'status' => 1,
'date' => $where['date'],
'category' => 'now_money',
];
$bill = app()->make(UserBillRepository::class)->search($bill_where)->where('type','in',['sys_inc_money','recharge'])->sum('number');
//充值消费金额
$bill_where = [
'pm' => 0,
'status' => 1,
'date' => $where['date'],
'category' => 'now_money',
];
$_bill = app()->make(UserBillRepository::class)->search($bill_where)->where('type','in',['presell','pay_product','sys_dec_money'])->sum('number');
//产生交易的商户数
$mer_number = $this->dao->search($where)->group('mer_id')->count();
$stat = [
[
'className' => 'el-icon-s-goods',
'count' => $count,
'field' => '元',
'name' => '订单收入总金额'
],
[
'className' => 'el-icon-s-order',
'count' => $refund_order,
'field' => '元',
'name' => '退款支出金额'
],
[
'className' => 'el-icon-s-cooperation',
'count' => $brokerage,
'field' => '元',
'name' => '佣金支出金额'
],
[
'className' => 'el-icon-s-cooperation',
'count' => $charge,
'field' => '元',
'name' => '平台手续费'
],
[
'className' => 'el-icon-s-finance',
'count' => $bill,
'field' => '元',
'name' => '充值金额'
],
[
'className' => 'el-icon-s-cooperation',
'count' => $_bill,
'field' => '元',
'name' => '充值消费金额'
],
[
'className' => 'el-icon-s-goods',
'count' => $mer_number,
'field' => '个',
'name' => '产生交易的商户数'
],
[
'className' => 'el-icon-s-goods',
'count' => $coupon,
'field' => '元',
'name' => '优惠券金额'
]
];
return compact('stat');
}
/**
* TODO 商户头部统计
* @param $where
* @return array
* @author Qinii
* @day 5/6/21
*/
public function getMerchantTitle($where)
{
//商户收入
$count = $this->dao->search($where)->where('financial_type','in',['order','mer_presell'])->sum('number');
//平台优惠券
$coupon = $this->dao->search($where)->where('financial_type','in',['order_platform_coupon','order_svip_coupon'])->sum('number');
//商户余额
$mer_money = app()->make(SupplyRepository::class)->search(['mer_id' => $where['is_mer']])->value('mer_money');
//最低提现额度
$extract_minimum_line = systemConfig('extract_minimum_line');
//商户可提现金额
$_line = bcsub($mer_money,$extract_minimum_line,2);
//退款支出金额
$refund_order = $this->dao->search($where)->where('financial_type','refund_order')->sum('number');
//佣金支出金额
$_brokerage = $this->dao->search($where)->where('financial_type','in',['brokerage_one','brokerage_two'])->sum('number');
$refund_brokerage = $this->dao->search($where)->where('financial_type','in',['refund_brokerage_one','refund_brokerage_two'])->sum('number');
$brokerage = bcsub($_brokerage,$refund_brokerage,2);
//平台手续费
$refund_true = $this->dao->search($where)->where('financial_type','in',['order_charge','presell_charge'])->sum('number');
$order_charge = $this->dao->search($where)->where('financial_type','refund_charge')->sum('number');
$charge = bcsub($refund_true,$order_charge,2);
//商户可提现金额
// $bill_order = app()->make(StoreOrderRepository::class)->search(['paid' => 1,'date' => $where['date'],'pay_type' => 0])->sum('pay_price');
$merLockMoney = app()->make(UserBillRepository::class)->merchantLickMoney($where['is_mer']);
$stat = [
[
'className' => 'el-icon-s-goods',
'count' => $count,
'field' => '元',
'name' => '商户收入'
],
[
'className' => 'el-icon-s-order',
'count' => $mer_money,
'field' => '元',
'name' => '商户余额'
],
[
'className' => 'el-icon-s-cooperation',
'count' => ($_line < 0) ? 0 : $_line,
'field' => '元',
'name' => '商户可提现金额'
],
[
'className' => 'el-icon-s-cooperation',
'count' => $refund_order,
'field' => '元',
'name' => '退款支出'
],
[
'className' => 'el-icon-s-finance',
'count' => $brokerage,
'field' => '元',
'name' => '佣金支出'
],
[
'className' => 'el-icon-s-cooperation',
'count' => $charge,
'field' => '元',
'name' => '平台手续费'
],
[
'className' => 'el-icon-s-cooperation',
'count' => $coupon,
'field' => '元',
'name' => '平台优惠券补贴'
],
[
'className' => 'el-icon-s-cooperation',
'count' => $merLockMoney,
'field' => '元',
'name' => '商户冻结金额'
],
];
return compact('stat');
}
/**
* TODO 月账单
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @author Qinii
* @day 3/23/21
*/
public function getAdminList(array $where,int $page,int $limit)
{
//日
if($where['type'] == 1){
$field = Db::raw('from_unixtime(unix_timestamp(create_time),\'%Y-%m-%d\') as time');
}else{
//月
if(!empty($where['date'])){
list($startTime, $endTime) = explode('-', $where['date']);
$firstday = date('Y/m/01', strtotime($startTime));
$lastday_ = date('Y/m/01', strtotime($endTime));
$lastday = date('Y/m/d', strtotime("$lastday_ +1 month -1 day"));
$where['date'] = $firstday.'-'.$lastday;
}
$field = Db::raw('from_unixtime(unix_timestamp(create_time),\'%Y-%m\') as time');
}
$query = $this->dao->search($where)->field($field)->group("time")->order('create_time DESC');
$count = $query->count();
$list = $query->page($page,$limit)->select()->each(function ($item) use($where){
$key = $where['is_mer'] ? $where['is_mer'].'_financial_record_list_'.$item['time'] : 'sys_financial_record_list_'.$item['time'];
if(($where['type'] == 1 && ($item['time'] == date('Y-m-d',time()))) || ($where['type'] == 2 && ($item['time'] == date('Y-m',time())))){
$income = ($this->countIncome($where['type'],$where,$item['time']))['number'];
$expend = ($this->countExpend($where['type'],$where,$item['time']))['number'];
$ret = [
'income' => $income,
'expend' => $expend ,
'charge' => bcsub($income,$expend,2),
];
}else{
if(!$ret = Cache::get($key)){
$income = ($this->countIncome($where['type'],$where,$item['time']))['number'] ;
$expend = ($this->countExpend($where['type'],$where,$item['time']))['number'] ;
$ret = [
'income' => $income,
'expend' => $expend ,
'charge' => bcsub($income,$expend,2),
];
Cache::tag('system')->set($key,$ret,24 * 3600);
}
}
$item['income'] = $ret['income'];
$item['expend'] = $ret['expend'];
$item['charge'] = $ret['charge'];
});
return compact('count','list');
}
/**
* TODO 平台详情
* @param int $type
* @param array $where
* @return mixed
* @author Qinii
* @day 3/23/21
*/
public function adminDetail(int $type,array $where)
{
$date_ = strtotime($where['date']);unset($where['date']);
$date = ($type == 1) ? date('Y-m-d',$date_) : date('Y-m',$date_);
$income = $this->countIncome($type,$where,$date);
$bill = $this->countBill($type,$date);
$expend = $this->countExpend($type,$where,$date);
$charge = bcsub($income['number'],$expend['number'],2);
$data['date'] = $date;
$data['income'] = [
'title' => '订单收入总金额',
'number' => $income['number'] ,
'count' => $income['count'].'笔',
'data' => [
['订单支付', $income['number_order'].'元', $income['count_order'].'笔'],
['退回优惠券补贴', $income['number_coupon'].'元', $income['count_coupon'].'笔'],
['退回会员优惠券补贴', $income['number_svipcoupon'].'元', $income['count_svipcoupon'].'笔'],
]
];
$data['bill'] = [
'title' => '充值金额',
'number' => $bill['number'] ,
'count' => $bill['count'].'笔',
'data' => []
];
$data['expend'] = [
'title' => '支出总金额',
'number' => $expend['number'] ,
'count' => $expend['count'].'笔',
'data' => [
['应付商户金额', $expend['number_order'] .'元', $expend['count_order'].'笔'],
['佣金', $expend['number_brokerage'] .'元', $expend['count_brokerage'].'笔'],
['返还手续费', $expend['number_charge'] .'元', $expend['count_charge'].'笔'],
['优惠券补贴',$expend['number_coupon'] .'元', $expend['count_coupon'].'笔'],
['会员优惠券补贴',$expend['number_svipcoupon'] .'元', $expend['count_svipcoupon'].'笔'],
]
];
$data['charge'] = [
'title' => '平台手续费收入总金额',
'number' => $charge ,
'count' => '',
'data' => []
];
return $data;
}
/**
* TODO 商户详情
* @param int $type
* @param array $where
* @return mixed
* @author Qinii
* @day 5/6/21
*/
public function merDetail(int $type,array $where)
{
$date_ = strtotime($where['date']); unset($where['date']);
$date = ($type == 1) ? date('Y-m-d',$date_) : date('Y-m',$date_);
$income = $this->countIncome($type,$where,$date);
$expend = $this->countExpend($type,$where,$date);
$charge = bcsub($income['number'],$expend['number'],2);
$data['date'] = $date;
$data['income'] = [
'title' => '订单收入总金额',
'number' => $income['number'] ,
'count' => $income['count'].'笔',
'data' => [
['订单支付', $income['number_order'].'元', $income['count_order'].'笔'],
['优惠券补贴', $income['number_coupon'].'元', $income['count_coupon'].'笔'],
['会员优惠券补贴', $income['number_svipcoupon'].'元', $income['count_svipcoupon'].'笔'],
]
];
$data['expend'] = [
'title' => '支出总金额',
'number' => $expend['number'] ,
'count' => $expend['count'].'笔',
'data' => [
[
'平台手续费',
bcsub($expend['number_order_charge'],$expend['number_charge'],2) .'元',
$expend['count_charge']+$expend['count_order_charge'].'笔'
],
[
'佣金',
bcsub($expend['number_brokerage'],$expend['number_refund_brokerage'],2) .'元',
$expend['count_brokerage'] + $expend['count_refund_brokerage'].'笔'
],
[
'商户退款',
$expend['number_refund'] .'元',
$expend['count_refund'].'笔'
],
[
'退还优惠券补贴',
$expend['number_coupon'] .'元',
$expend['count_coupon'].'笔'
],
[
'退还会员优惠券补贴',
$expend['number_svipcoupon'] .'元',
$expend['count_svipcoupon'].'笔'
],
]
];
$data['charge'] = [
'title' => '应入账总金额',
'number' => $charge ,
'count' => '',
'data' => []
];
return $data;
}
/**
* TODO 总收入
* @param $type
* @param $date
* @return array
* @author Qinii
* @day 3/23/21
*/
public function countIncome($type, $where, $date)
{
$financialType = ['order','order_presell','presell','mer_presell'];
[$data['count_order'],$data['number_order']] = $this->dao->getDataByType($type, $where, $date, $financialType);
if ($where['is_mer']){
$financialType = ['order_platform_coupon'];
} else {
$financialType = ['refund_platform_coupon'];
}
[ $data['count_coupon'], $data['number_coupon']] = $this->dao->getDataByType($type, $where, $date, $financialType);
if ($where['is_mer']){
$financialType = ['order_svip_coupon'];
} else {
$financialType = ['refund_svip_coupon'];
}
[ $data['count_svipcoupon'], $data['number_svipcoupon']] = $this->dao->getDataByType($type, $where, $date, $financialType);
$data['count'] = $data['count_order'];
$data['number'] = bcadd($data['number_coupon'],$data['number_order'],2);
return $data;
}
/**
* TODO 充值金额
* @param $type
* @param $date
* @return array
* @author Qinii
* @day 3/23/21
*/
public function countBill($type, $date)
{
$bill_where = [
'pm' => 1,
'status' => 1,
'category' => 'now_money',
];
$query = app()->make(UserBillRepository::class)->search($bill_where)->where('type','in',['sys_inc_money','recharge']);
//充值消费金额
if($type == 1) $query->whereDay('create_time', $date);
if($type == 2) $query->whereMonth('create_time',$date);
$count = $query->count();
$number = $query->sum('number');
return compact('count','number');
}
/**
* TODO 平台总支出
* @param $type
* @param $date
* @return array
* @author Qinii
* @day 3/23/21
*/
public function countExpend($type, $where, $date)
{
/**
* 平台支出
* 商户的收入 order_true + 佣金 brokerage_one,brokerage_two + 手续费 refund_charge + 商户预售收入 presell_true
*
* 商户支出
* 退回收入 refund_order + (佣金 brokerage_one,brokerage_two - 退回佣金 refund_brokerage_two,refund_brokerage_one + (手续费 order_charge + 预售手续费 presell_charge - 平台退给商户的手续费 refund_charge
*/
// 退回佣金
$financialType = ['brokerage_one','brokerage_two'];
[$data['count_brokerage'],$data['number_brokerage']] = $this->dao->getDataByType($type, $where, $date, $financialType);
// 退回 手续费
$financialType = ['refund_charge'];
[$data['count_charge'],$data['number_charge']] = $this->dao->getDataByType($type, $where, $date, $financialType);
if($where['is_mer']){ //商户的
//退回 收入
$financialType = ['refund_order'];
[$data['count_refund'],$data['number_refund']] = $this->dao->getDataByType($type, $where, $date, $financialType);
//平台手续费
$financialType = ['order_charge','presell_charge'];
[$data['count_order_charge'],$data['number_order_charge']] = $this->dao->getDataByType($type, $where, $date, $financialType);
//退回佣金
$financialType = ['refund_brokerage_two','refund_brokerage_one'];
[$data['count_refund_brokerage'],$data['number_refund_brokerage']] = $this->dao->getDataByType($type, $where, $date, $financialType);
//退回给平台的优惠券金额
$financialType = ['refund_platform_coupon'];
[$data['count_coupon'], $data['number_coupon']] = $this->dao->getDataByType($type, $where, $date, $financialType);
//退回给平台的会员优惠券金额
$financialType = ['refund_svip_coupon'];
[$data['count_svipcoupon'], $data['number_svipcoupon']] = $this->dao->getDataByType($type, $where, $date, $financialType);
//佣金 brokerage_one,brokerage_two - 退回佣金 refund_brokerage_two,refund_brokerage_one
$number = bcsub($data['number_brokerage'],$data['number_refund_brokerage'],3);
//平台手续费 = order_charge + 预售手续费 presell_charge - 平台退给商户的手续费 refund_charge
$number_1 = bcsub($data['number_order_charge'],$data['number_charge'],3);
//退回收入 refund_order + 退回佣金
$number_2 = bcadd(bcadd($data['number_refund'],$data['number_coupon'],2),$data['number_svipcoupon'],2);
$data['count'] = $data['count_brokerage'] + $data['count_refund'] + $data['count_order_charge'] + $data['count_refund'] + $data['count_refund_brokerage'] + $data['count_svipcoupon'];
$data['number'] =bcadd(bcadd($number_2,$number,3),$number_1,2);
}else{ //平台的
// 退回 订单实际获得金额
$financialType = ['order_true','presell_true'];
[$data['count_order'],$data['number_order']] = $this->dao->getDataByType($type, $where, $date, $financialType);
//付给商户的优惠券抵扣金额
$financialType = ['order_platform_coupon'];
[$data['count_coupon'], $data['number_coupon']] = $this->dao->getDataByType($type, $where, $date, $financialType);
//付给商户的svip优惠券抵扣金额
$financialType = ['order_svip_coupon'];
[$data['count_svipcoupon'], $data['number_svipcoupon']] = $this->dao->getDataByType($type, $where, $date, $financialType);
$number = bcadd($data['number_brokerage'],$data['number_order'],2);
$number_1 = bcadd(bcadd($number,$data['number_coupon'],2),$data['number_svipcoupon'],2);
$data['count'] = $data['count_brokerage'] + $data['count_order'] + $data['count_charge'];
$data['number'] = bcadd($number_1,$data['number_charge'],2);
}
return $data;
}
/**
* TODO 手续费
* @param $where
* @param $date
* @return mixed
* @author Qinii
* @day 3/24/21
*/
public function countCharge($type,$where,$date)
{
$financialType = ['order_charge'];
[$count, $number] = $this->dao->getDataByType($type, $where, $date, $financialType);
return compact('count','number');
}
/**
* TODO 退款
* @param $where
* @param $date
* @return mixed
* @author Qinii
* @day 3/24/21
*/
public function countRefund($type,$where,$date)
{
$financialType = ['refund_order'];
[$count, $number] = $this->dao->getDataByType($type, $where, $date, $financialType);
return compact('count','number');
}
public function merchantFinancial(array $where, int $page, int $limit)
{
$query = app()->make(SupplyRepository::class)->search($where);
$count = $query->count();
$merchant = $query->page($page, $limit)->setOption('field',[])->field('mer_id,mer_name,status,is_del,mer_money')->select();
$financialRecordRepository = app()->make(FinancialRecordRepository::class);
$list = [];
foreach ($merchant as $item) {
$key = date('YmdH').'_'.json_encode($item);
if (!$ret = Cache::get($key)) {
//商户累计应入账金额
$_where['is_mer'] = $item['mer_id'];
$income = $financialRecordRepository->countIncome(0,$_where,'')['number'];
$expend = $financialRecordRepository->countExpend(0,$_where,'')['number'];
$ret = [
'income' => $income,
'expend' => $expend ,
'charge' => bcsub($income,$expend,2),
];
//商户累计交易额
$ret['sum'] = $financialRecordRepository->search($_where)->where('financial_type','in',['order','mer_presell'])->sum('number');
//商户可提现金额
//最低提现额度
$extract_minimum_line = systemConfig('extract_minimum_line');
//商户可提现金额
$_line = bcsub($item['mer_money'],$extract_minimum_line,2);
$ret['line'] = $_line > 0 ? $_line : 0;
$ret['mer_money'] = $item['mer_money'];
$ret = json_encode($ret,JSON_UNESCAPED_UNICODE);
Cache::set($key, $ret,1800);
}
$item['account'] = json_decode($ret,true);
$list[] = $item;
}
return compact('count','list');
}
}

View File

@ -0,0 +1,382 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\repositories\system\supply;
use app\common\dao\BaseDao;
use app\common\dao\system\supply\SupplyAdminDao;
use app\common\model\system\supply\Supply;
use app\common\model\system\supply\SupplyAdmin;
use app\common\repositories\BaseRepository;
use app\common\repositories\system\auth\RoleRepository;
use crmeb\exceptions\AuthException;
use crmeb\services\JwtTokenService;
use FormBuilder\Exception\FormBuilderException;
use FormBuilder\Factory\Elm;
use FormBuilder\Form;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\exception\ValidateException;
use think\facade\Cache;
use think\facade\Config;
use think\facade\Route;
use think\Model;
/**
* Class SupplyRepository
* @package app\common\repositories\system\supply
* @mixin SupplyAdminDao
* @author xaboy
* @day 2020-04-16
*/
class SupplyAdminRepository extends BaseRepository
{
const PASSWORD_TYPE_ADMIN = 1;
const PASSWORD_TYPE_MERCHANT = 2;
const PASSWORD_TYPE_SELF = 3;
/**
* SupplyAdminRepository constructor.
* @param SupplyAdminDao $dao
*/
public function __construct(SupplyAdminDao $dao)
{
$this->dao = $dao;
}
/**
* @param $merId
* @param array $where
* @param $page
* @param $limit
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-04-18
*/
public function getList($merId, array $where, $page, $limit)
{
$query = $this->dao->search($merId, $where, 1);
$count = $query->count();
$list = $query->page($page, $limit)->hidden(['pwd', 'is_del'])->select();
$topAccount = $this->dao->merIdByAccount($merId);
foreach ($list as $k => $role) {
if ($topAccount)
$list[$k]['account'] = $topAccount . '@' . $role['account'];
$list[$k]['rule_name'] = $role->roleNames();
}
return compact('list', 'count');
}
/**
* @param int $merId
* @param int|null $id
* @param array $formData
* @return Form
* @throws FormBuilderException
* @author xaboy
* @day 2020-04-18
*/
public function form(int $merId, ?int $id = null, array $formData = []): Form
{
$form = Elm::createForm(is_null($id) ? Route::buildUrl('SupplyAdminCreate')->build() : Route::buildUrl('SupplyAdminUpdate', ['id' => $id])->build());
$rules = [
Elm::select('roles', '身份:', [])->options(function () use ($merId) {
$data = app()->make(RoleRepository::class)->getAllOptions($merId);
$options = [];
foreach ($data as $value => $label) {
$options[] = compact('value', 'label');
}
return $options;
})->placeholder('请选择省份')->multiple(true),
Elm::input('real_name', '管理员姓名:')->placeholder('请输入管理员姓名'),
Elm::input('account', '账号:')->placeholder('请输入账号')->required(),
Elm::input('phone', ' 联系电话:')->placeholder('请输入联系电话'),
];
if (!$id) {
$rules[] = Elm::password('pwd', '密码:')->placeholder('请输入密码')->required();
$rules[] = Elm::password('againPassword', '确认密码:')->placeholder('请输入确认密码')->required();
}
$rules[] = Elm::switches('status', '是否开启:', 1)->inactiveValue(0)->activeValue(1)->inactiveText('关')->activeText('开');
$form->setRule($rules);
return $form->setTitle(is_null($id) ? '添加管理员' : '编辑管理员')->formData($formData);
}
/**
* @param int $merId
* @param int $id
* @return Form
* @throws DataNotFoundException
* @throws DbException
* @throws FormBuilderException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-04-18
*/
public function updateForm(int $merId, int $id)
{
return $this->form($merId, $id, $this->dao->get($id)->toArray());
}
/**
* @param Merchant $merchant
* @param $account
* @param $pwd
* @return BaseDao|Model
* @author xaboy
* @day 2020-04-17
*/
public function createMerchantAccount(Supply $merchant, $account, $pwd)
{
$pwd = $this->passwordEncode($pwd);
$data = compact('pwd', 'account') + [
'mer_id' => $merchant->mer_id,
'real_name' => $merchant->real_name,
'phone' => $merchant->mer_phone,
'level' => 0
];
return $this->create($data);
}
/**
* @param $password
* @return bool|string
* @author xaboy
* @day 2020-04-17
*/
public function passwordEncode($password)
{
return password_hash($password, PASSWORD_BCRYPT);
}
/**
* @param string $account
* @param string $password
* @return array|Model|null
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-04-17
*/
public function login(string $account, string $password)
{
event('admin.merLogin.before',compact('account', 'password'));
$accountInfo = explode('@', $account, 2);
if (count($accountInfo) === 1) {
$adminInfo = $this->dao->accountByTopAdmin($accountInfo[0]);
} else {
$merId = $this->dao->accountByMerchantId($accountInfo[0]);
if (!$merId){
$key = 'mer_login_failuree_'.$account;
$numb = Cache::get($key) ?? 0;
$numb++;
Cache::set($key,$numb,15*60);
throw new ValidateException('账号或密码错误');
}
$adminInfo = $this->dao->accountByAdmin($accountInfo[1], $merId);
}
if (!$adminInfo || !password_verify($password, $adminInfo->pwd)){
$key = 'mer_login_failuree_'.$account;
$numb = Cache::get($key) ?? 0;
$numb++;
Cache::set($key,$numb,15*60);
throw new ValidateException('账号或密码错误');
}
if ($adminInfo['status'] != 1)
throw new ValidateException('账号已关闭');
/**
* @var SupplyRepository $supplyRepository
*/
$SupplyRepository = app()->make(SupplyRepository::class);
$merchant = $SupplyRepository->get($adminInfo->mer_id);
if (!$merchant)
throw new ValidateException('商户不存在');
if (!$merchant['status'])
throw new ValidateException('商户已被锁定');
$adminInfo->last_time = date('Y-m-d H:i:s');
$adminInfo->last_ip = app('request')->ip();
$adminInfo->login_count++;
$adminInfo->save();
event('admin.merLogin',compact('adminInfo'));
return $adminInfo;
}
/**
* @param string $token
* @param int $exp
* @author xaboy
* @day 2020-04-10
*/
public function cacheToken(string $token, int $exp)
{
Cache::set('mer_' . $token, time() + $exp, $exp);
}
/**
* @param string $token
* @author xaboy
* @day 2020-04-17
*/
public function checkToken(string $token)
{
$has = Cache::has('mer_' . $token);
if (!$has)
throw new AuthException('无效的token');
$lastTime = Cache::get('mer_' . $token);
if (($lastTime + (intval(Config::get('admin.token_valid_exp', 15))) * 60) < time())
throw new AuthException('token 已过期');
}
/**
* @param string $token
* @author xaboy
* @day 2020-04-17
*/
public function updateToken(string $token)
{
Cache::set('mer_' . $token, time(), intval(Config::get('admin.token_valid_exp', 15)) * 60);
}
/**
* @param string $token
* @author xaboy
* @day 2020-04-17
*/
public function clearToken(string $token)
{
Cache::delete('mer_' . $token);
}
/**
* @param SupplyAdmin $admin
* @return array
* @author xaboy
* @day 2020-04-17
*/
public function createToken(SupplyAdmin $admin)
{
$service = new JwtTokenService();
$exp = intval(Config::get('admin.token_exp', 3));
$token = $service->createToken($admin->merchant_admin_id, 'mer', strtotime("+ {$exp}hour"));
$this->cacheToken($token['token'], $token['out']);
return $token;
}
/**
* @param string $key
* @param string $code
* @author xaboy
* @day 2020-04-17
*/
public function checkCode(string $key, string $code)
{
if (!env('DEVELOPMENT',false)){
$_code = Cache::get('am_captcha' . $key);
if (!$_code) {
throw new ValidateException('验证码过期');
}
if (strtolower($_code) != strtolower($code)) {
throw new ValidateException('验证码错误');
}
//删除code
Cache::delete('am_captcha' . $key);
}
}
/**
* @param string $code
* @return string
* @author xaboy
* @day 2020-04-17
*/
public function createLoginKey(string $code)
{
$key = uniqid(microtime(true), true);
Cache::set('am_captcha' . $key, $code, Config::get('admin.captcha_exp', 5) * 60);
return $key;
}
/**
* @param int $id
* @param int $userType
* @return Form
* @throws FormBuilderException
* @author xaboy
* @day 2020-04-20
*/
public function passwordForm(int $id, $userType = 2)
{
$action = 'SupplyAdminPassword';
if ($userType == self::PASSWORD_TYPE_ADMIN)
$action = 'systemSupplyAdminPassword';
else if ($userType == self::PASSWORD_TYPE_SELF)
$action = 'SupplyAdminEditPassword';
$form = Elm::createForm(Route::buildUrl($action, $userType == self::PASSWORD_TYPE_SELF ? [] : compact('id'))->build(), [
$rules[] = Elm::password('pwd', '密码:')->placeholder('请输入密码')->required(),
$rules[] = Elm::password('againPassword', '确认密码:')->placeholder('请输入确认密码')->required(),
]);
return $form->setTitle('修改密码');
}
/**
* @param array $formData
* @return Form
* @throws FormBuilderException
* @author xaboy
* @day 2020-04-20
*/
public function editForm(array $formData)
{
$form = Elm::createForm(Route::buildUrl('SupplyAdminEdit')->build());
$form->setRule([
Elm::input('real_name', '管理员姓名:')->placeholder('请输入管理员姓名')->required(),
Elm::input('phone', '联系电话:')->placeholder('请输入联系电话')
]);
return $form->setTitle('修改信息')->formData($formData);
}
/**
* @param int $id
* @param array $data
* @return int
* @throws DbException
* @author xaboy
* @day 2020-04-18
*/
public function update(int $id, array $data)
{
if (isset($data['roles']))
$data['roles'] = implode(',', $data['roles']);
return $this->dao->update($id, $data);
}
}

View File

@ -0,0 +1,565 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\repositories\system\supply;
use app\common\dao\system\supply\SupplyAppymentsDao;
use app\common\model\system\supply\SupplyApplyments;
use app\common\repositories\BaseRepository;
use crmeb\jobs\SendSmsJob;
use crmeb\services\ImageWaterMarkService;
use crmeb\services\UploadService;
use crmeb\services\WechatService;
use FormBuilder\Factory\Elm;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Queue;
use think\facade\Route;
class SupplyApplymentsRepository extends BaseRepository
{
const IDCARD = 'IDENTIFICATION_TYPE_MAINLAND_IDCARD'; //:中国大陆居民-身份证
const PASSPORT = 'IDENTIFICATION_TYPE_OVERSEA_PASSPORT'; //:其他国家或地区居民-护照
const HONGKONG = 'IDENTIFICATION_TYPE_HONGKONG'; //:中国香港居民–来往内地通行证
const MACAO = 'IDENTIFICATION_TYPE_MACAO'; //:中国澳门居民–来往内地通行证
const TAIWAN = 'IDENTIFICATION_TYPE_TAIWAN'; //:中国台湾居民–来往大陆通行证
const FOREIGN_RESIDENT = 'IDENTIFICATION_TYPE_FOREIGN_RESIDENT'; //:外国人居留证
const MACAO_RESIDENT = 'IDENTIFICATION_TYPE_HONGKONG_MACAO_RESIDENT'; //:港澳居民证
const TAIWAN_RESIDENT = 'IDENTIFICATION_TYPE_TAIWAN_RESIDENT'; //:台湾居民证
public function __construct(SupplyAppymentsDao $dao)
{
$this->dao = $dao;
}
/**
* TODO 申请
* @param array $data
* @param $merId
* @return mixed
* @author Qinii
* @day 6/23/21
*/
public function create(array $data,$merId)
{
$count = $this->dao->getSearch(['mer_id' => $merId])->count('*');
if($count) throw new ValidateException('此商户已存在申请信息');
$out_request_no = $this->getOutRequestNo($merId);
$ret['mer_name'] = $data['merchant_shortname'];
$ret['out_request_no'] = $out_request_no;
$data['out_request_no'] = $out_request_no;
$ret['info'] = json_encode($data,JSON_UNESCAPED_UNICODE);
$ret['mer_id'] = $merId;
$this->dao->create($ret);
}
/**
* TODO 整理请求数据
* @param $info
* @return mixed
* @author Qinii
* @day 6/24/21
*/
public function sltData($info)
{
foreach ($info as $key => $value){
if(is_object($value)){
$value = (array)$value;
}
$data[$key] = $value;
}
if (isset($data['need_account_info'])) unset($data['need_account_info']);
$data['id_doc_type'] = $this->getIdDocType($data['id_doc_type']);
//营业执照
if(isset($data['business_license_info'])){
if(isset($data['business_license_info']['business_license_copy'])) {
$business_license_copy = $data['business_license_info']['business_license_copy']->media_id;
unset($data['business_license_info']['business_license_copy']);
$data['business_license_info']['business_license_copy'] = $business_license_copy;
}
if(isset($data['business_license_info']['business_time'])){
$organization_time = json_encode($data['business_license_info']['business_time'],JSON_UNESCAPED_UNICODE);
$data['business_license_info']['business_time'] = $organization_time;
}
}
//组织机构代码
if(isset($data['organization_cert_info'])){
if(isset($data['organization_cert_info']['organization_copy'])) {
$organization_copy = $data['organization_cert_info']['organization_copy']->media_id;
unset($data['organization_cert_info']['organization_copy']);
$data['organization_cert_info']['organization_copy'] = $organization_copy;
}
if(isset($data['organization_cert_info']['organization_time'])){
$organization_time = json_encode($data['organization_cert_info']['organization_time'],JSON_UNESCAPED_UNICODE);
$data['organization_cert_info']['organization_time'] = $organization_time;
}
}
//身份证
if(isset($data['id_card_info'])){
if(isset($data['id_card_info']['id_card_copy'])) {
$id_card_copy = $data['id_card_info']['id_card_copy']->media_id;
unset($data['id_card_info']['id_card_copy']);
$data['id_card_info']['id_card_copy'] = $id_card_copy;
}
if(isset($data['id_card_info']['id_card_national'])) {
$id_card_national = $data['id_card_info']['id_card_national']->media_id;
unset($data['id_card_info']['id_card_national']);
$data['id_card_info']['id_card_national'] = $id_card_national;
}
}
//银行
if(isset($data['account_info'])) {
if(is_array($data['account_info']['bank_address_code'])){
$bank_address_code = (string)$data['account_info']['bank_address_code'][2];
unset($data['account_infoaccount_info']['bank_address_code']);
$data['account_info']['bank_address_code'] = $bank_address_code;
}
$data['account_info']['bank_account_type'] = (string)$data['account_info']['bank_account_type'];
}
//管理员
if(isset($data['contact_info'])) {
$data['contact_info']['contact_type'] = (string)$data['contact_info']['contact_type'];
if ($data['contact_info']['contact_type'] == 65) {
unset(
$data['contact_info']['contact_id_doc_copy'],
$data['contact_info']['contact_id_doc_copy_back'],
$data['contact_info']['contact_id_doc_period_begin'],
$data['contact_info']['contact_id_doc_period_end'],
$data['contact_info']['business_authorization_letter'],
$data['contact_info']['contact_id_doc_type']
);
}
if(isset($data['contact_info']['contact_id_doc_period_end']))
{
$doc_ = json_encode($data['contact_info']['contact_id_doc_period_end'],JSON_UNESCAPED_UNICODE);
$data['contact_info']['contact_id_doc_period_end'] = $doc_;
}
if(isset($data['contact_info']['contact_id_doc_type']))
{
$data['contact_info']['contact_id_doc_type'] = $this->getIdDocType($data['contact_info']['contact_id_doc_type']);
}
if(isset($data['contact_info']['contact_id_doc_copy'])) {
$contact_id_doc_copy = $data['contact_info']['contact_id_doc_copy']->media_id;
unset($data['contact_info']['contact_id_doc_copy']);
$data['contact_info']['contact_id_doc_copy'] = $contact_id_doc_copy;
}
if(isset($data['contact_info']['contact_id_doc_copy_back'])) {
$contact_id_doc_copy_back = $data['contact_info']['contact_id_doc_copy_back']->media_id;
unset($data['contact_info']['contact_id_doc_copy_back']);
$data['contact_info']['contact_id_doc_copy_back'] = $contact_id_doc_copy_back;
}
if(isset($data['contact_info']['business_authorization_letter'])) {
$business_authorization_letter = $data['contact_info']['business_authorization_letter']->media_id;
unset($data['contact_info']['business_authorization_letter']);
$data['contact_info']['business_authorization_letter'] = $business_authorization_letter;
}
}
//其他证件
if(isset($data['id_doc_info'])){
$doc_ = json_encode($data['id_doc_info']['doc_period_end'],JSON_UNESCAPED_UNICODE);
$data['id_doc_info']['doc_period_end'] = $doc_;
if(isset($data['id_doc_info']['id_doc_copy'])) {
$id_doc_copy = $data['id_doc_info']['id_doc_copy']->media_id;
unset($data['id_doc_info']['id_doc_copy']);
$data['id_doc_info']['id_doc_copy'] = $id_doc_copy;
}
if(isset($data['id_doc_info']['id_doc_copy_back'])) {
$id_doc_copy_back = $data['id_doc_info']['id_doc_copy_back']->media_id;
unset($data['id_doc_info']['id_doc_copy_back']);
$data['id_doc_info']['id_doc_copy_back'] = $id_doc_copy_back;
}
}
//店铺信息
if(isset($data['sales_scene_info']['store_qr_code']) && $data['sales_scene_info']['store_qr_code']){
$store_qr_code= $data['sales_scene_info']['store_qr_code']->media_id;
unset($data['sales_scene_info']['store_qr_code']);
$data['sales_scene_info']['store_qr_code'] = $store_qr_code;
}
//特殊资质
if(isset($data['qualifications']) && !empty($data['qualifications'])){
$qualifications = [];
foreach ($data['qualifications'] as $item){
$qualifications[] = $item->media_id;
}
unset($data['qualifications']);
$data['qualifications'] = json_encode($qualifications,JSON_UNESCAPED_UNICODE);
}
//补充材料
if(isset($data['business_addition_pics']) && !empty($data['business_addition_pics'])){
$business_addition_pics = [];
foreach ($data['business_addition_pics'] as $item){
$business_addition_pics[] = $item->media_id;
}
unset($data['business_addition_pics']);
$data['business_addition_pics'] = json_encode($business_addition_pics,JSON_UNESCAPED_UNICODE);
}
$data['organization_type'] = (string)$data['organization_type'];
return $data;
}
/**
* TODO 生成申请单
* @param $merId
* @return string
* @author Qinii
* @day 6/24/21
*/
public function getOutRequestNo($merId)
{
list($msec, $sec) = explode(' ', microtime());
$msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
$key = 'MERCHANT' . $merId . '_' . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369));
do{
$ret = $this->dao->getSearch(['out_request_no' => $key])->count();
}while($ret);
return $key;
}
/**
* TODO 详情
* @param $id
* @param $merId
* @return array|\think\Model|null
* @author Qinii
* @day 6/22/21
*/
public function detail(int $merId)
{
if($merId) $where['mer_id'] = $merId;
$data = $this->dao->getSearch($where)->find();
if(!$data) return [];
$data['info'] = json_decode($data['info']);
return $data;
}
/**
* TODO 编辑
* @param $id
* @param $data
* @author Qinii
* @day 6/22/21
*/
public function edit($id,$data)
{
//申请状态: 0.平台未提交,-1.平台驳回10.平台提交审核中11.需用户操作 20.已完成30.已冻结40.驳回
$get = $this->dao->get($id);
if(!$get) throw new ValidateException('数据不存在');
if(!in_array($get['status'],[-1,0,40])) throw new ValidateException('数据当前状态不可编辑');
$data['out_request_no'] = $get['out_request_no'];
$ret['info'] = json_encode($data,JSON_UNESCAPED_UNICODE);
$ret['status'] = 0;
$ret['message'] = '';
$this->dao->update($id,$ret);
}
/**
* TODO 查询申请状态
* @param $merId
* @author Qinii
* @day 6/23/21
*/
public function check($merId)
{
$ret = $this->dao->getSearch(['mer_id' => $merId])->find();
$data = [];
if($ret['status'] < 10) throw new ValidateException('平台审核中...');
if($ret['status'] == 20) throw new ValidateException('申请已完成,请勿重复查询');
try{
$data = WechatService::create()->applyments()->getApplicationById($ret->applyment_id);
}catch (\Exception $exception){
}
if(!$data){
$data = WechatService::create()->applyments()->getApplicationByNo($ret->out_request_no);
if($data){
$ret->applyment_id = $data['applyment_id'];
$ret->save();
}
}
if($data) {
$result = $this->getApplymentState($data);
$this->sendSms($ret,$result['status']);
return Db::transaction(function () use ($merId, $ret, $result) {
if (isset($result['sub_mchid'])) $this->profitsharingAdd($ret,$result);
$this->dao->update($ret->mer_applyments_id, $result);
});
}else{
return ;
}
}
/**
* TODO 添加分账商户
* @param SupplyApplyments $ret
* @param $result
* @author Qinii
* @day 6/24/21
*/
public function profitsharingAdd(SupplyApplyments $ret,$result)
{
$info = json_decode($ret['info']);
$profitsharing = [
"type" => 'MERCHANT_ID',
"account" => $result['sub_mchid'],
// "name" => $info->account_info->account_name,
"relation_type" => "PLATFORM"
];
$res = WechatService::create()->applyments()->profitsharingAdd($profitsharing);
if(isset($res['account'])) app()->make(MerchantRepository::class)->update($ret->mer_id, ['sub_mchid' => $res['account'] ]);
}
/**
* TODO 查询返回的状态整理
* @param $data
* @return array
* @author Qinii
* @day 6/23/21
*/
public function getApplymentState($data)
{
//CHECKING资料校验中
//ACCOUNT_NEED_VERIFY待账户验证
//AUDITING审核中
//REJECTED已驳回
//NEED_SIGN待签约
//FINISH完成
//FROZEN已冻结
$result = [];
$message = '';
$status = 10;
switch (($data['applyment_state']))
{
//申请状态: 0.平台未提交,-1.平台驳回10.平台提交审核中11.需用户操作 20.已完成30.已冻结40.驳回
case 'ACCOUNT_NEED_VERIFY':
$status = 11;
if(isset($data['account_validation'])){
$ret = $data['account_validation'];
$message = '通过申请银行账号向以下信息汇款完成验证,'.PHP_EOL;
$message .= '收款方信息:'.PHP_EOL;
$message .= "汇款金额:".$ret['pay_amount'].'(单位:分);'.PHP_EOL;
$message .= "收款卡号:".$ret['destination_account_number'].';'.PHP_EOL;
$message .= "收款户名:".$ret['destination_account_name'].';'.PHP_EOL;
$message .= "开户银行:".$ret['destination_account_bank'].';'.PHP_EOL;
$message .= "省市信息:".$ret['city'].';'.PHP_EOL;
$message .= "备注信息:".$ret['remark'].';'.PHP_EOL;
$message .= "汇款截止时间:".$ret['deadline'].'。';
}
if(isset($data['legal_validation_url'])){
$message = '商户法人通过此链接完成验证:'.$data['legal_validation_url'];
}
break;
case 'REJECTED':
$message = '';
foreach ($data['audit_detail'] as $datum){
$message .= '参数名称:'.$datum['param_name'].PHP_EOL;
$message .= '驳回原因:'.$datum['reject_reason'].PHP_EOL;
}
$status = 40;
break;
case 'NEED_SIGN':
$status = 11;
$message = $data['sign_url'];
break;
case 'FINISH':
$result['sub_mchid'] = $data['sub_mchid'];
$status = 20;
$message = '完成';
break;
case 'FROZEN':
$status = 30;
break;
default:
break;
}
$result['status'] = $status;
$result['message'] = $message;
return $result;
}
/**
* TODO 上传图片
* @param $field
* @return array
* @author Qinii
* @day 6/21/21
*/
public function uploadImage($field,$water)
{
$upload = UploadService::create(1);
$info = $upload->to('def')->move($field);
if ($info === false) throw new ValidateException($upload->getError());
$res = $upload->getUploadInfo();
$res['path'] = app()->getRootPath().'public'.($res['dir']);
$res['dir'] = tidy_url($res['dir']);
if($res['path']) $ret = WechatService::create()->uploadImages([$res]);
if(!$water) app()->make(ImageWaterMarkService::class)->run($res['path']);
return $ret;
}
/**
* TODO 列表
* @param array $where
* @param int $page
* @param int $limit
* @return array
* @author Qinii
* @day 6/24/21
*/
public function getList(array $where, int $page, int $limit)
{
$query = $this->dao->getSearch($where)->with(['merchant' => function($query){
$query->field('mer_id,mer_name');
}])->order('create_time DESC');
$count = $query->count();
$list = $query->page($page,$limit)->select();
return compact('count','list');
}
/**
* TODO 审核操作
* @param int $id
* @param array $data
* @author Qinii
* @day 6/23/21
*/
public function switchWithStatus(int $id,array $data)
{
$ret = $this->dao->get($id);
if(!$ret) throw new ValidateException('数据不存在');
if($ret['status'] !== 0) throw new ValidateException('请勿重复审核');
if($data['status'] == 10){
$info = $this->sltData(json_decode($ret['info']));
Db::transaction(function() use($id,$info){
WechatService::create()->applyments()->submitApplication($info);
$this->dao->update($id,['status' => 10]);
});
}
if($data['status'] == -1) {
$this->dao->update($id,$data);
$this->sendSms($ret,-1);
}
return ;
}
/**
* TODO 发送短信
* @param SupplyApplyments $ret
* @param $type
* @author Qinii
* @day 7/9/21
*/
public function sendSms(SupplyApplyments $ret,$type)
{
if(!systemConfig('applyments_sms')) return ;
$info = json_decode($ret['info']);
switch ($type)
{
case -1:
$tmp = 'APPLYMENTS_FAIL';
break;
case 11:
$tmp = 'APPLYMENTS_SIGN';
break;
case 20:
$tmp = 'APPLYMENTS_SUCCESS';
break;
case 40:
$tmp = 'APPLYMENTS_FAIL';
break;
default:
return ;
break;
}
Queue::push(SendSmsJob::class,['tempId' => $tmp, 'id' => ['phone'=> $info->contact_info->mobile_phone, 'mer_name' => $info->merchant_shortname]]);
}
/**
* TODO 查询商户的分账信息
* @param $merId
* @return mixed
* @author Qinii
* @day 6/24/21
*/
public function getMerchant($merId)
{
$data = app()->make(MerchantRepository::class)->get($merId);
if(!$data) throw new ValidateException('数据不存在');
if(!$data['sub_mchid']) throw new ValidateException('该商户不是分账商户');
$ret = WechatService::create()->applyments()->getSubMerchant($data['sub_mchid']);
return $ret;
}
/**
* TODO 备注
* @param $id
* @return \FormBuilder\Form
* @author Qinii
* @day 7/5/21
*/
public function markForm($id)
{
$data = $this->dao->get($id);
$form = Elm::createForm(Route::buildUrl('systemSupplyApplymentsMarrkSave', ['id' => $id])->build());
$form->setRule([
Elm::text('mark', '备注:', $data['mark'])->placeholder('请输入备注')->required(),
]);
return $form->setTitle('修改备注');
}
/**
* TODO 经营者/法人证件类型
* @param $key
* @return array|mixed
* @author Qinii
* @day 6/22/21
*/
public function getIdDocType($key)
{
$data = [
1 => self::IDCARD,
2 => self::PASSPORT,
3 => self::HONGKONG,
4 => self::MACAO,
5 => self::TAIWAN,
6 => self::FOREIGN_RESIDENT,
7 => self::MACAO_RESIDENT,
8 => self::TAIWAN_RESIDENT,
];
if($key) return $data[$key];
return $data;
}
}

View File

@ -0,0 +1,121 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\repositories\system\supply;
use app\common\dao\system\supply\SupplyCategoryDao;
use app\common\repositories\BaseRepository;
use FormBuilder\Exception\FormBuilderException;
use FormBuilder\Factory\Elm;
use FormBuilder\Form;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Route;
/**
* Class SupplyCategoryRepository
* @package app\common\repositories\system\supply
* @author xaboy
* @day 2020-05-06
* @mixin SupplyCategoryDao
*/
class SupplyCategoryRepository extends BaseRepository
{
/**
* @var SupplyCategoryDao
*/
protected $dao;
/**
* SupplyCategoryRepository constructor.
* @param SupplyCategoryDao $dao
*/
public function __construct(SupplyCategoryDao $dao)
{
$this->dao = $dao;
}
/**
* @param array $where
* @param $page
* @param $limit
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-05-06
*/
public function getList(array $where, $page, $limit)
{
$query = $this->search($where);
$count = $query->count($this->dao->getPk());
$list = $query->page($page, $limit)->select()->toArray();
foreach ($list as $k => $v) {
$list[$k]['commission_rate'] = ($v['commission_rate'] > 0 ? bcmul($v['commission_rate'], 100, 2) : 0) . '%';
}
return compact('count', 'list');
}
/**
* @param int|null $id
* @param array $formData
* @return Form
* @throws FormBuilderException
* @author xaboy
* @day 2020-05-06
*/
public function form(?int $id = null, array $formData = [])
{
$action = Route::buildUrl(is_null($id) ? 'systemMerchantCategoryCreate' : 'systemMerchantCategoryUpdate', is_null($id) ? [] : compact('id'))->build();
$form = Elm::createForm($action, [
Elm::input('category_name', '分类名称:')->placeholder('请输入分类名称')->required(),
Elm::number('commission_rate', '手续费(%)', 0)->required()->max(100)->precision(2)
]);
return $form->formData($formData)->setTitle(is_null($id) ? '添加商户分类' : '编辑商户分类');
}
/**
* @param $id
* @return Form
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws FormBuilderException
* @author xaboy
* @day 2020-05-06
*/
public function updateForm($id)
{
$res = $this->dao->get($id)->toArray();
$res['commission_rate'] = $res['commission_rate'] > 0 ? bcmul($res['commission_rate'], 100, 2) : 0;
return $this->form($id, $res);
}
/**
* 筛选分类
* @Author:Qinii
* @Date: 2020/9/15
* @return array
*/
public function getSelect()
{
$query = $this->search([])->field('merchant_category_id,category_name');
$list = $query->select()->toArray();
return $list;
}
}

View File

@ -0,0 +1,169 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\repositories\system\supply;
use app\common\repositories\BaseRepository;
use app\common\repositories\system\config\ConfigValueRepository;
use crmeb\jobs\SendSmsJob;
use FormBuilder\Factory\Elm;
use app\common\dao\system\supply\SupplyIntentionDao;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Queue;
use think\facade\Route;
/**
* @mixin SupplyIntentionDao
*/
class SupplyIntentionRepository extends BaseRepository
{
public function __construct(SupplyIntentionDao $dao)
{
$this->dao = $dao;
}
public function getList(array $where, $page, $limit)
{
$query = $this->dao->search($where);
$count = $query->count();
$list = $query->page($page, $limit)->order('create_time DESC , status ASC')->with(['merchantCategory', 'merchantType'])->select();
return compact('count', 'list');
}
public function detail($id, ?int $uid)
{
$where = ['mer_intention_id' => $id];
if (!is_null($uid)) {
$where['uid'] = $uid;
}
return $this->dao->search($where)->find();
}
public function updateIntention($id, array $data)
{
if ($this->dao->existsWhere(['mer_intention_id' => $id, 'status' => '1']))
throw new ValidateException('当前状态不能修改');
$data['images'] = implode(',', (array)$data['images']);
$data['status'] = 0;
$data['fail_msg'] = '';
return $this->dao->update($id, $data);
}
public function markForm($id)
{
$data = $this->dao->get($id);
$form = Elm::createForm(Route::buildUrl('systemMerchantIntentionMark', ['id' => $id])->build());
$form->setRule([
Elm::textarea('mark', '备注:', $data['mark'])->placeholder('请输入备注')->required(),
]);
return $form->setTitle('修改备注');
}
public function statusForm($id)
{
$form = Elm::createForm(Route::buildUrl('systemMerchantIntentionStatus', ['id' => $id])->build());
$form->setRule([
Elm::select('status', '审核状态:', 1)->options([
['value' => 1, 'label' => '同意'],
['value' => 2, 'label' => '拒绝'],
])->control([
[
'value' => 1,
'rule' => [
Elm::radio('create_mer', '自动创建商户:', 1)->options([
['value' => 1, 'label' => '创建'],
['value' => 2, 'label' => '不创建'],
])
]
],
[
'value' => 2,
'rule' => [
Elm::textarea('fail_msg', '失败原因:', '信息填写有误')->placeholder('请输入失败原因')
]
]
]),
]);
return $form->setTitle('修改审核状态');
}
public function updateStatus($id, $data)
{
$create = $data['create_mer'] == 1;
unset($data['create_mer']);
$intention = $this->search(['mer_intention_id' => $id])->find();
if (!$intention)
throw new ValidateException('信息不存在');
if ($intention->status)
throw new ValidateException('状态有误,修改失败');
$config = systemConfig(['broadcast_room_type', 'broadcast_goods_type']);
$margin = app()->make(SupplyTypeRepository::class)->get($intention['mer_type_id']);
$data['is_margin'] = $margin['is_margin'] ?? -1;
$data['margin'] = $margin['margin'] ?? 0;
$merData = [];
$smsData = [];
if ($create == 1) {
$password = substr($intention['phone'], -6);
$merData = [
'mer_name' => $intention['mer_name'],
'mer_phone' => $intention['phone'],
'mer_account' => $intention['phone'],
'category_id' => $intention['merchant_category_id'],
'type_id' => $intention['mer_type_id'],
'real_name' => $intention['name'],
'status' => 1,
'is_audit' => 1,
'is_bro_room' => $config['broadcast_room_type'] == 1 ? 0 : 1,
'is_bro_goods' => $config['broadcast_goods_type'] == 1 ? 0 : 1,
'mer_password' => $password,
'is_margin' => $margin['is_margin'] ?? -1,
'margin' => $margin['margin'] ?? 0,
'mark' => $margin['margin'] ?? 0,
];
$data['fail_msg'] = '';
$smsData = [
'date' => date('m月d日', strtotime($intention->create_time)),
'mer' => $intention['mer_name'],
'phone' => $intention['phone'],
'pwd' => $password ?? '',
'site_name' => systemConfig('site_name'),
];
}
if ($data['status'] == 2) {
$smsData = [
'phone' => $intention['phone'],
'date' => date('m月d日', strtotime($intention->create_time)),
'mer' => $intention['mer_name'],
'site' => systemConfig('site_name'),
];
}
Db::transaction(function () use ($config, $intention, $data, $create,$margin,$merData,$smsData) {
if ($data['status'] == 1) {
if ($create == 1) {
$merchant = app()->make(SupplyRepository::class)->createMerchant($merData);
app()->make(ConfigValueRepository::class)->setFormData(['mer_certificate' => $intention['images']], $merchant->mer_id);
$data['mer_id'] = $merchant->mer_id;
Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_SUCCESS', 'id' => $smsData]);
}
} else {
Queue::push(SendSmsJob::class, ['tempId' => 'APPLY_MER_FAIL', 'id' => $smsData]);
}
$intention->save($data);
});
}
}

View File

@ -0,0 +1,878 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\repositories\system\supply;
use app\common\dao\system\supply\SupplyDao;
use app\common\model\store\order\StoreOrder;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\coupon\StoreCouponRepository;
use app\common\repositories\store\coupon\StoreCouponUserRepository;
use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\store\product\ProductCopyRepository;
use app\common\repositories\store\product\ProductRepository;
use app\common\repositories\store\shipping\ShippingTemplateRepository;
use app\common\repositories\store\StoreCategoryRepository;
use app\common\repositories\system\attachment\AttachmentCategoryRepository;
use app\common\repositories\system\attachment\AttachmentRepository;
use app\common\repositories\system\operate\OperateLogRepository;
use app\common\repositories\system\serve\ServeOrderRepository;
use app\common\repositories\user\UserBillRepository;
use app\common\repositories\user\UserRelationRepository;
use app\common\repositories\user\UserVisitRepository;
use crmeb\jobs\ChangeSupplyStatusJob;
use crmeb\jobs\ClearSupplyStoreJob;
use crmeb\services\QrcodeService;
use crmeb\services\WechatService;
use FormBuilder\Exception\FormBuilderException;
use FormBuilder\Factory\Elm;
use FormBuilder\Form;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Queue;
use think\facade\Route;
use think\Model;
/**
* Class SupplyRepository
* @package app\common\repositories\system\merchant
* @mixin SupplyDao
* @author xaboy
* @day 2020-04-16
*/
class SupplyRepository extends BaseRepository
{
/**
* SupplyRepository constructor.
* @param SupplyDao $dao
*/
public function __construct(SupplyDao $dao)
{
$this->dao = $dao;
}
/**
* @param array $where
* @param $page
* @param $limit
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-04-16
*/
public function lst(array $where, $page, $limit)
{
$query = $this->dao->search($where);
$count = $query->count($this->dao->getPk());
$list = $query->page($page, $limit)->setOption('field', [])
->with([
'admin' => function ($query) {
$query->field('mer_id,account');
},
'merchantCategory',
'merchantType'
])
->field('sort,mer_id,mer_name,real_name,mer_phone,mer_address,mark,status,create_time,is_best,is_trader,type_id,category_id,copy_product_num,export_dump_num,is_margin,margin,ot_margin,mer_avatar,margin_remind_time')->select();
return compact('count', 'list');
}
public function count($where)
{
$where['status'] = 1;
$valid = $this->dao->search($where)->count();
$where['status'] = 0;
$invalid = $this->dao->search($where)->count();
return compact('valid', 'invalid');
}
/**
* @param int|null $id
* @param array $formData
* @return Form
* @throws FormBuilderException
* @author xaboy
* @day 2020-04-16
*/
public function form(?int $id = null, array $formData = [])
{
$form = Elm::createForm(is_null($id) ? Route::buildUrl('systemMerchantCreate')->build() : Route::buildUrl('systemMerchantUpdate', ['id' => $id])->build());
$is_margin = 0;
if ($formData && $formData['is_margin'] == 10) $is_margin = 1;
/** @var MerchantCategoryRepository $make */
$make = app()->make(SupplyCategoryRepository::class);
$merchantTypeRepository = app()->make(SupplyTypeRepository::class);
$options = $merchantTypeRepository->getOptions();
$margin = $merchantTypeRepository->getMargin();
$config = systemConfig(['broadcast_room_type', 'broadcast_goods_type']);
$rule = [
Elm::input('mer_name', '商户名称:')->placeholder('请输入商户名称')->required(),
Elm::select('category_id', '商户分类:')->options(function () use ($make) {
return $make->allOptions();
})->placeholder('请选择商户分类')->requiredNum(),
Elm::select('type_id', '店铺类型:')->disabled($is_margin)->options($options)->requiredNum()->col(12)->control($margin)->placeholder('请选择店铺类型'),
Elm::input('mer_account', '商户账号:')->placeholder('请输入商户账号')->required()->disabled(!is_null($id))->required(!is_null($id)),
Elm::password('mer_password', '登录密码:')->placeholder('请输入登陆密码')->required()->disabled(!is_null($id))->required(!is_null($id)),
Elm::input('real_name', '商户姓名:')->placeholder('请输入商户姓名'),
Elm::input('mer_phone', '商户手机号:')->col(12)->placeholder('请输入商户手机号')->required(),
Elm::number('commission_rate', '手续费(%)')->col(12),
Elm::input('mer_keyword', '商户关键字:')->placeholder('请输入商户关键字')->col(12),
Elm::input('mer_address', '商户地址:')->placeholder('请输入商户地址'),
Elm::input('sub_mchid', '微信分账商户号:')->placeholder('请输入微信分账商户号'),
Elm::textarea('mark', '备注:')->placeholder('请输入备注'),
Elm::number('sort', '排序:', 0)->precision(0)->max(99999),
$id ? Elm::hidden('status', 1) : Elm::switches('status', '是否开启:', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(12),
Elm::switches('is_bro_room', '直播间审核:', $config['broadcast_room_type'] == 1 ? 0 : 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(12),
Elm::switches('is_audit', '产品审核:', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(12),
Elm::switches('is_bro_goods', '直播间商品审核:', $config['broadcast_goods_type'] == 1 ? 0 : 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(12),
Elm::switches('is_best', '是否推荐:')->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(12),
Elm::switches('is_trader', '是否自营:')->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(12),
];
$form->setRule($rule);
return $form->setTitle(is_null($id) ? '添加商户' : '编辑商户')->formData($formData);
}
/**
* @param array $formData
* @return Form
* @throws FormBuilderException
* @author xaboy
* @day 2020/6/25
*/
public function merchantForm(array $formData = [])
{
$form = Elm::createForm(Route::buildUrl('merchantUpdate')->build());
$rule = [
Elm::textarea('mer_info', '店铺简介:')->placeholder('请输入店铺简介')->required(),
Elm::input('service_phone', '服务电话:')->placeholder('请输入服务电话')->required(),
Elm::frameImage('mer_banner', '店铺Banner(710*200px)', '/' . config('admin.merchant_prefix') . '/setting/uploadPicture?field=mer_banner&type=1')->icon('el-icon-camera')->modal(['modal' => false])->width('1000px')->height('600px')->props(['footer' => false]),
Elm::frameImage('mer_avatar', '店铺头像(120*120px)', '/' . config('admin.merchant_prefix') . '/setting/uploadPicture?field=mer_avatar&type=1')->icon('el-icon-camera')->modal(['modal' => false])->width('1000px')->height('600px')->props(['footer' => false]),
Elm::switches('mer_state', '是否开启:', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关')->activeText('开')->col(12),
];
$form->setRule($rule);
return $form->setTitle('编辑店铺信息')->formData($formData);
}
/**
* @param $id
* @return Form
* @throws FormBuilderException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-04-16
*/
public function updateForm($id)
{
$data = $this->dao->get($id)->toArray();
/** @var MerchantAdminRepository $make */
$make = app()->make(SupplyAdminRepository::class);
$data['mer_account'] = $make->merIdByAccount($id);
$data['mer_password'] = '***********';
if($data['category_id'] == 0){
$data['category_id'] = '';
}
if($data['type_id'] == 0){
$data['type_id'] = '';
}
return $this->form($id, $data);
}
/**
* @param array $data
* @author xaboy
* @day 2020-04-17
*/
public function createMerchant(array $data)
{
if ($this->fieldExists('mer_name', $data['mer_name']))
throw new ValidateException('商户名已存在');
if ($data['mer_phone'] && isPhone($data['mer_phone']))
throw new ValidateException('请输入正确的手机号');
$merchantCategoryRepository = app()->make(SupplyCategoryRepository::class);
$adminRepository = app()->make(SupplyAdminRepository::class);
if (!$data['category_id'] || !$merchantCategoryRepository->exists($data['category_id']))
throw new ValidateException('商户分类不存在');
if ($adminRepository->fieldExists('account', $data['mer_account']))
throw new ValidateException('账号已存在');
/** @var MerchantAdminRepository $make */
$make = app()->make(SupplyAdminRepository::class);
$margin = app()->make(SupplyTypeRepository::class)->get($data['type_id']);
$data['is_margin'] = $margin['is_margin'] ?? 0;
$data['margin'] = $margin['margin'] ?? 0;
$data['ot_margin'] = $margin['margin'] ?? 0;
$admin_info = [];
if(isset($data['admin_info'])){
$admin_info = $data['admin_info'] ?: [];
unset($data['admin_info']);
}
return Db::transaction(function () use ($data, $make,$admin_info) {
$account = $data['mer_account'];
$password = $data['mer_password'];
unset($data['mer_account'], $data['mer_password']);
$merchant = $this->dao->create($data);
$make->createMerchantAccount($merchant, $account, $password);
app()->make(ShippingTemplateRepository::class)->createDefault($merchant->mer_id);
app()->make(ProductCopyRepository::class)->defaulCopyNum($merchant->mer_id);
// 记录商户创建日志
if (!empty($admin_info) && !empty($update_infos)) {
event('create_operate_log', [
'category' => OperateLogRepository::PLATFORM_CREATE_MERCHANT,
'data' => [
'merchant' => $merchant,
'admin_info' => $admin_info,
],
]);
}
return $merchant;
});
}
/**
* @Author:Qinii
* @Date: 2020/5/30
* @param $where
* @param $page
* @param $limit
* @return array
*/
public function getList($where, $page, $limit, $userInfo)
{
$field = 'care_count,is_trader,type_id,mer_id,mer_banner,mini_banner,mer_name, mark,mer_avatar,product_score,service_score,postage_score,sales,status,is_best,create_time,long,lat,is_margin';
$where['status'] = 1;
$where['mer_state'] = 1;
$where['is_del'] = 0;
if (isset($where['location'])) {
$data = @explode(',', (string)$where['location']);
if (2 != count(array_filter($data ?: []))) {
unset($where['location']);
} else {
$where['location'] = [
'lat' => (float)$data[0],
'long' => (float)$data[1],
];
}
}
if ($where['keyword'] !== '') {
app()->make(UserVisitRepository::class)->searchMerchant($userInfo ? $userInfo['uid'] : 0, $where['keyword']);
}
$query = $this->dao->search($where)->with(['type_name']);
$count = $query->count();
$status = systemConfig('mer_location') && isset($where['location']);
$list = $query->page($page, $limit)->setOption('field', [])->field($field)->select()
->each(function ($item) use ($status, $where) {
if ($status && $item['lat'] && $item['long'] && isset($where['location']['lat'], $where['location']['long'])) {
$distance = getDistance($where['location']['lat'], $where['location']['long'], $item['lat'], $item['long']);
if ($distance < 0.9) {
$distance = max(bcmul($distance, 1000, 0), 1).'m';
if ($distance == '1m') {
$distance = '100m以内';
}
} else {
$distance .= 'km';
}
$item['distance'] = $distance;
}
$item['recommend'] = isset($where['delivery_way']) ? $item['CityRecommend'] : $item['AllRecommend'];
return $item;
});
return compact('count', 'list');
}
/**
* @Author:Qinii
* @Date: 2020/5/30
* @param int $id
* @return array|Model|null
*/
public function merExists(int $id)
{
return ($this->dao->get($id));
}
/**
* @Author:Qinii
* @Date: 2020/5/30
* @param $id
* @param $userInfo
* @return array|Model|null
*/
public function detail($id, $userInfo)
{
$merchant = $this->dao->apiGetOne($id)->hidden([
"real_name", "mer_phone", "reg_admin_id", "sort", "is_del", "is_audit", "is_best", "mer_state", "bank", "bank_number", "bank_name", 'update_time',
'financial_alipay', 'financial_bank', 'financial_wechat', 'financial_type','mer_take_phone'
]);
$merchant->append(['type_name', 'isset_certificate', 'services_type']);
$merchant['care'] = false;
if ($userInfo)
$merchant['care'] = $this->getCareByUser($id, $userInfo->uid);
return $merchant;
}
/**
* @Author:Qinii
* @Date: 2020/5/30
* @param int $merId
* @param int $userId
* @return bool
*/
public function getCareByUser(int $merId, int $userId)
{
if (app()->make(UserRelationRepository::class)->getWhere(['type' => 10, 'type_id' => $merId, 'uid' => $userId]))
return true;
return false;
}
/**
* @Author:Qinii
* @Date: 2020/5/30
* @param $merId
* @param $where
* @param $page
* @param $limit
* @param $userInfo
* @return mixed
*/
public function productList($merId, $where, $page, $limit, $userInfo)
{
return app()->make(ProductRepository::class)->getApiSearch($merId, $where, $page, $limit, $userInfo);
}
/**
* @Author:Qinii
* @Date: 2020/5/30
* @param int $id
* @return mixed
*/
public function categoryList(int $id)
{
return app()->make(StoreCategoryRepository::class)->getApiFormatList($id, 1);
}
public function wxQrcode($merId)
{
$siteUrl = systemConfig('site_url');
$name = md5('mwx' . $merId . date('Ymd')) . '.jpg';
$attachmentRepository = app()->make(AttachmentRepository::class);
$imageInfo = $attachmentRepository->getWhere(['attachment_name' => $name]);
if (isset($imageInfo['attachment_src']) && strstr($imageInfo['attachment_src'], 'http') !== false && curl_file_exist($imageInfo['attachment_src']) === false) {
$imageInfo->delete();
$imageInfo = null;
}
if (!$imageInfo) {
$codeUrl = rtrim($siteUrl, '/') . '/pages/store/home/index?id=' . $merId; //二维码链接
if (systemConfig('open_wechat_share')) {
$qrcode = WechatService::create(false)->qrcodeService();
$codeUrl = $qrcode->forever('_scan_url_mer_' . $merId)->url;
}
$imageInfo = app()->make(QrcodeService::class)->getQRCodePath($codeUrl, $name);
if (is_string($imageInfo)) throw new ValidateException('二维码生成失败');
$imageInfo['dir'] = tidy_url($imageInfo['dir'], null, $siteUrl);
$attachmentRepository->create(systemConfig('upload_type') ?: 1, -2, $merId, [
'attachment_category_id' => 0,
'attachment_name' => $imageInfo['name'],
'attachment_src' => $imageInfo['dir']
]);
$urlCode = $imageInfo['dir'];
} else $urlCode = $imageInfo['attachment_src'];
return $urlCode;
}
public function routineQrcode($merId)
{
$name = md5('smrt' . $merId . date('Ymd')) . '.jpg';
return tidy_url(app()->make(QrcodeService::class)->getRoutineQrcodePath($name, 'pages/store/home/index', 'id=' . $merId), 0);
}
public function copyForm(int $id)
{
$form = Elm::createForm(Route::buildUrl('systemMerchantChangeCopy', ['id' => $id])->build());
$form->setRule([
Elm::input('copy_num', '复制次数:', $this->dao->getCopyNum($id))->disabled(true)->readonly(true),
Elm::radio('type', '修改类型:', 1)
->setOptions([
['value' => 1, 'label' => '增加'],
['value' => 2, 'label' => '减少'],
]),
Elm::number('num', '修改数量:', 0)->required()
]);
return $form->setTitle('修改复制商品次数');
}
public function deleteForm($id)
{
$form = Elm::createForm(Route::buildUrl('systemMerchantDelete', ['id' => $id])->build());
$form->setRule([
Elm::radio('type', '删除方式:', 0)->options([
['label' => '仅删除数据', 'value' => 0],
['label' => '删除数据和资源', 'value' => 1]
])->appendRule('suffix', [
'type' => 'div',
'style' => ['color' => '#999999'],
'domProps' => [
'innerHTML' =>'删除后将不可恢复,请谨慎操作!',
]
]),
]);
return $form->setTitle( '删除商户');
}
public function delete($id)
{
Db::transaction(function () use ($id) {
$this->dao->update($id, ['is_del' => 1]);
app()->make(SupplyAdminRepository::class)->deleteMer($id);
Queue::push(ClearSupplyStoreJob::class, ['mer_id' => $id]);
});
}
/**
* TODO 删除商户的图片及原件
* @param $id
* @author Qinii
* @day 2023/5/8
*/
public function clearAttachment($id)
{
$attachment_category_id = app()->make(AttachmentCategoryRepository::class)->getSearch([])
->where('mer_id',$id)
->column('attachment_category_id');
$AttachmentRepository = app()->make(AttachmentRepository::class);
$attachment_id = $AttachmentRepository->getSearch([])
->whereIn('attachment_category_id',$attachment_category_id)
->column('attachment_id');
if ($attachment_id) $AttachmentRepository->batchDelete($attachment_id,$id);
}
/**
* TODO 清理删除商户但没有删除的商品数据
* @author Qinii
* @day 5/15/21
*/
public function clearRedundancy()
{
$rets = (int)$this->dao->search(['is_del' => 1])->column('mer_id');
if (empty($rets)) return;
$productRepository = app()->make(ProductRepository::class);
$storeCouponRepository = app()->make(StoreCouponRepository::class);
$storeCouponUserRepository = app()->make(StoreCouponUserRepository::class);
foreach ($rets as $ret) {
try {
$productRepository->clearMerchantProduct($ret);
$storeCouponRepository->getSearch([])->where('mer_id', $ret)->update(['is_del' => 1, 'status' => 0]);
$storeCouponUserRepository->getSearch([])->where('mer_id', $ret)->update(['is_fail' => 1, 'status' => 2]);
} catch (\Exception $exception) {
throw new ValidateException($exception->getMessage());
}
}
}
public function addLockMoney(int $merId, string $orderType, int $orderId, float $money)
{
if ($money <= 0) return;
if (systemConfig('mer_lock_time')) {
app()->make(UserBillRepository::class)->incBill($merId, 'mer_lock_money', $orderType, [
'link_id' => ($orderType === 'order' ? 1 : 2) . $orderId,
'mer_id' => $merId,
'status' => 0,
'title' => '商户冻结余额',
'number' => $money,
'mark' => '商户冻结余额',
'balance' => 0
]);
} else {
$this->dao->addMoney($merId, $money);
}
}
public function checkCrmebNum(int $merId, string $type)
{
$merchant = $this->dao->get($merId);
switch ($type) {
case 'copy':
if (!systemConfig('copy_product_status')) {
throw new ValidateException('复制商品未开启');
}
if (!$merchant['copy_product_num']) {
throw new ValidateException('复制商品剩余次数不足');
}
break;
case 'dump':
if (!systemConfig('crmeb_serve_dump')) {
throw new ValidateException('电子面单未开启');
}
if (!$merchant['export_dump_num']) {
throw new ValidateException('电子面单剩余次数不足');
}
break;
}
return true;
}
public function subLockMoney(int $merId, string $orderType, int $orderId, float $money)
{
if ($money <= 0) return;
$make = app()->make(UserBillRepository::class);
$bill = $make->search(['category' => 'mer_lock_money', 'type' => $orderType, 'mer_id' => $merId, 'link_id' => ($orderType === 'order' ? 1 : 2) . $orderId, 'status' => 0])->find();
if (!$bill) {
$this->dao->subMoney($merId, $money);
} else {
$make->decBill($merId, 'mer_refund_money', $orderType, [
'link_id' => ($orderType === 'order' ? 1 : 2) . $orderId,
'mer_id' => $merId,
'status' => 1,
'title' => '商户冻结余额退款',
'number' => $money,
'mark' => '商户冻结余额退款',
'balance' => 0
]);
}
}
public function computedLockMoney(StoreOrder $order)
{
Db::transaction(function () use ($order) {
$money = 0;
$make = app()->make(UserBillRepository::class);
$bill = $make->search(['category' => 'mer_lock_money', 'type' => 'order', 'link_id' => '1' . $order->order_id, 'status' => 0])->find();
if ($bill) {
$money = bcsub($bill->number, $make->refundMerchantMoney($bill->link_id, $bill->type, $bill->mer_id), 2);
if ($order->presellOrder) {
$presellBill = $make->search(['category' => 'mer_lock_money', 'type' => 'presell', 'link_id' => '2' . $order->presellOrder->presell_order_id, 'status' => 0])->find();
if ($presellBill) {
$money = bcadd($money, bcsub($presellBill->number, $make->refundMerchantMoney($presellBill->link_id, $presellBill->type, $presellBill->mer_id), 2), 2);
$presellBill->status = 1;
$presellBill->save();
}
}
$bill->status = 1;
$bill->save();
}
if ($money > 0) {
app()->make(UserBillRepository::class)->incBill($order->uid, 'mer_computed_money', 'order', [
'link_id' => $order->order_id,
'mer_id' => $order->mer_id,
'status' => 0,
'title' => '商户待解冻余额',
'number' => $money,
'mark' => '交易完成,商户待解冻余额' . floatval($money) . '元',
'balance' => 0
]);
}
});
}
public function checkMargin($merId, $typeId)
{
$merchant = $this->dao->get($merId);
$is_margin = 0;
$margin = 0;
if ($merchant['is_margin'] == 10) {
$margin = $merchant['margin'];
$is_margin = $merchant['is_margin'];
$ot_margin = $merchant['ot_margin'];
} else {
$marginData = app()->make(SupplyTypeRepository::class)->get($typeId);
if ($marginData) {
$is_margin = $marginData['is_margin'];
$margin = $marginData['margin'];
$ot_margin = $marginData['margin'];
}
}
return compact('is_margin', 'margin','ot_margin');
}
public function setMarginForm(int $id)
{
$merchant = $this->dao->get($id);
if ($merchant->is_margin !== 10) {
throw new ValidateException('商户无保证金可扣');
}
$form = Elm::createForm(Route::buildUrl('systemMarginSet')->build());
$form->setRule([
[
'type' => 'span',
'title' => '商户名称:',
'native' => false,
'children' => [(string) $merchant->mer_name]
],
[
'type' => 'span',
'title' => '商户ID',
'native' => false,
'children' => [(string) $merchant->mer_id]
],
[
'type' => 'span',
'title' => '商户保证金额度:',
'native' => false,
'children' => [(string) $merchant->ot_margin]
],
[
'type' => 'span',
'title' => '商户剩余保证金:',
'native' => false,
'children' => [(string) $merchant->margin]
],
Elm::hidden('mer_id', $merchant->mer_id),
Elm::number('number', '保证金扣除金额:', 0)->max($merchant->margin)->precision(2)->required(),
Elm::text('mark', '保证金扣除原因:')->placeholder('请输入保证金扣除原因')->required(),
]);
return $form->setTitle('扣除保证金');
}
/**
* TODO
* @param $data
* @return \think\response\Json
* @author Qinii
* @day 2/7/22
*/
public function setMargin($data)
{
$merechant = $this->dao->get($data['mer_id']);
if ($merechant->is_margin !== 10)
throw new ValidateException('商户未支付保证金或已申请退款');
if ($data['number'] < 0)
throw new ValidateException('扣除保证金额不能小于0');
if (bccomp($merechant->margin, $data['number'], 2) == -1)
throw new ValidateException('扣除保证金额不足');
$data['balance'] = bcsub($merechant->margin, $data['number'], 2);
$data['mark'] = $data['mark'].'【 操作者:'. request()->adminId().'/'.request()->adminInfo()->real_name .'】';
$userBillRepository = app()->make(UserBillRepository::class);
Db::transaction(function () use ($merechant, $data,$userBillRepository) {
$merechant->margin = $data['balance'];
if (systemConfig('margin_remind_switch') == 1) {
$day = systemConfig('margin_remind_day') ?: 0;
if($day) {
$time = strtotime(date('Y-m-d 23:59:59',strtotime("+ $day day",time())));
$merechant->margin_remind_time = $time;
} else {
$merechant->status = 0;
}
}
$merechant->save();
$userBillRepository->bill(0, 'mer_margin', $data['type'], 0, $data);
});
}
public function changeDeliveryBalance($merId,$number)
{
$merechant = $this->dao->get($merId);
if (bccomp($merechant->delivery_balance, $number, 2) == -1) {
throw new ValidateException('余额不足,请先充值(配送费用:'.$number.'元)');
}
Db::transaction(function () use ($merechant, $number) {
$merechant->delivery_balance = bcsub($merechant->delivery_balance, $number, 2);
$merechant->save();
});
}
public function localMarginForm(int $id)
{
$merchant = $this->dao->get($id);
if (!in_array($merchant->is_margin,[1,10])) throw new ValidateException('商户无待缴保证金');
if ($merchant->is_margin == 10) {
$number = bcsub($merchant->ot_margin,$merchant->margin,2);
$_number = $merchant->margin;
} else {
$number = $merchant->margin;
$_number = 0;
}
$form = Elm::createForm(Route::buildUrl('systemMarginLocalSet',['id' => $id])->build());
$form->setRule([
[
'type' => 'span',
'title' => '商户名称:',
'native' => false,
'children' => [(string) $merchant->mer_name]
],
[
'type' => 'span',
'title' => '商户ID',
'native' => false,
'children' => [(string) $merchant->mer_id]
],
[
'type' => 'span',
'title' => '商户保证金额度:',
'native' => false,
'children' => [(string) $merchant->ot_margin]
],
[
'type' => 'span',
'title' => '商户剩余保证金:',
'native' => false,
'children' => [(string) $_number]
],
[
'type' => 'span',
'title' => '待缴保证金金额:',
'native' => false,
'children' => [(string) $number]
],
Elm::hidden('number', $number),
Elm::textarea('mark', '备注:', $merchant->mark),
Elm::radio('status', '状态:', 0)->options([
['value' => 0, 'label' => '未缴纳'],
['value' => 1, 'label' => '已缴纳']]
)
]);
return $form->setTitle('线下缴纳保证金');
}
public function localMarginSet($id, $data)
{
$merchant = $this->dao->get($id);
if (!$merchant) throw new ValidateException('商户不存在');
if (!$data['status']) {
$merchant->mark = $data['mark'];
$merchant->save();
} else {
if (!in_array($merchant->is_margin,[1,10])) throw new ValidateException('商户无待缴保证金');
if ($data['number'] < 0) throw new ValidateException('缴纳保证金额有误:'.$data['number']);
$storeOrderRepository = app()->make(StoreOrderRepository::class);
$userBillRepository = app()->make(UserBillRepository::class);
$serveOrderRepository = app()->make(ServeOrderRepository::class);
$order_sn = $storeOrderRepository->getNewOrderId(StoreOrderRepository::TYPE_SN_SERVER_ORDER);
$balance = $merchant->is_margin == 1 ? $data['number'] : bcadd($data['number'],$merchant->margin,2);
$serveOrder = [
'meal_id' => 0,
'pay_type'=> ServeOrderRepository::PAY_TYPE_SYS,
'order_sn'=> $order_sn,
'pay_price'=>$data['number'],
'order_info'=> json_encode(['type_id' => 0, 'is_margin' => 10, 'margin' => $data['number'], 'ot_margin' => $balance,]),
'type' => ServeOrderRepository::TYPE_MARGIN,
'status' => 1,
'mer_id' => $id,
'pay_time' => date('Y-m-d H:i:s',time())
];
$bill = [
'title' => '线下补缴保证金',
'mer_id' => $merchant['mer_id'],
'number' => $data['number'],
'mark'=> '操作者:'.request()->adminId().'/'.request()->adminInfo()->real_name,
'balance'=> $balance,];
// 商户操作记录
event('create_operate_log', [
'category' => OperateLogRepository::PLATFORM_EDIT_MERCHANT_AUDIT_MARGIN,
'data' => [
'merchant' => $merchant,
'admin_info' => request()->adminInfo(),
'update_infos' => ['status' => 10, 'action' => '线下补缴保证金', 'number' => $data['number']]
],
]);
Db::transaction(function () use ($merchant, $data,$userBillRepository,$bill,$balance,$serveOrder,$serveOrderRepository) {
$merchant->margin = $balance;
$merchant->margin_remind_time = null;
$merchant->is_margin = 10;
$merchant->mark = $data['mark'];
$merchant->save();
$serveOrderData = $serveOrderRepository->create($serveOrder);
$bill['link_id'] = $serveOrderData->order_id;
$userBillRepository->bill(0, 'mer_margin', 'local_margin', 1, $bill);
});
}
}
public function changeMerchantStatus()
{
if (systemConfig('margin_remind_switch') !== '1') return true;
$day = systemConfig('margin_remind_day') ?: 0;
$data = $this->dao->search(['margin' => 10])->whereRaw('ot_margin > margin')->select();
foreach ($data as $datum) {
if (is_null($datum->margin_remind_time)) {
if($day) {
$time = strtotime(date('Y-m-d 23:59:59',strtotime("+ $day day",time())));
$this->margin_remind_time = $time;
} else {
$this->status = 0;
}
} else {
if ($datum->margin_remind_time <= time()) {
$datum->status = 0;
Queue::push(ChangeSupplyStatusJob::class,$datum->mer_id);
}
}
$datum->save();
}
}
public function getPaidToMarginLst($where, $page, $limit)
{
$query = $this->dao->search($where);
$count = $query->count($this->dao->getPk());
$list = $query->page($page, $limit)->setOption('field', [])
->with(['merchantType','marginOrder'])
->field('sort,mer_id,mer_name,real_name,mer_phone,mer_address,mark,status,create_time,is_best,is_trader,type_id,category_id,copy_product_num,export_dump_num,is_margin,margin,ot_margin,mer_avatar,margin_remind_time')->select();
return compact('count', 'list');
}
/**
* TODO 平台后台获取商户信息
* @param $id
* @author Qinii
* @day 2023/7/1
*/
public function adminDetail($id)
{
$data = $this->dao->getWhere(['mer_id' => $id],'*',['merchantType','merchantCategory'])->toArray();
$make = app()->make(SupplyAdminRepository::class);
$data['mer_account'] = $make->merIdByAccount($id);
$data['mer_password'] = '***********';
if($data['category_id'] == 0){
$data['category_id'] = '';
}
if($data['type_id'] == 0){
$data['type_id'] = '';
}
$data['mer_certificate'] = merchantConfig($id, 'mer_certificate');
return $data;
}
}

View File

@ -0,0 +1,143 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\repositories\system\supply;
use app\common\dao\system\supply\SupplyTypeDao;
use app\common\repositories\BaseRepository;
use app\common\repositories\system\auth\MenuRepository;
use app\common\repositories\system\RelevanceRepository;
use FormBuilder\Factory\Elm;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\Route;
/**
* @mixin SupplyTypeDao
*/
class SupplyTypeRepository extends BaseRepository
{
public function __construct(SupplyTypeDao $dao)
{
$this->dao = $dao;
}
public function getList($page, $limit)
{
$query = $this->dao->search()->with(['auth']);
$count = $query->count();
$list = $query->page($page, $limit)->order('mer_type_id DESC')->select()->append(['merchant_count']);
foreach ($list as $item){
$item['auth_ids'] = array_column($item['auth']->toArray(), 'right_id');
unset($item['auth']);
}
return compact('count', 'list');
}
public function getSelect()
{
$query = $this->search([])->field('mer_type_id,type_name');
return $query->select()->toArray();
}
public function delete(int $id)
{
return Db::transaction(function () use ($id) {
$this->dao->delete($id);
app()->make(SupplyRepository::class)->clearTypeId($id);
app()->make(RelevanceRepository::class)->batchDelete($id, RelevanceRepository::TYPE_MERCHANT_AUTH);
});
}
public function create(array $data)
{
return Db::transaction(function () use ($data) {
$auth = array_filter(array_unique($data['auth']));
unset($data['auth']);
$type = $this->dao->create($data);
$inserts = [];
foreach ($auth as $id) {
$inserts[] = [
'left_id' => $type->mer_type_id,
'right_id' => (int)$id,
'type' => RelevanceRepository::TYPE_MERCHANT_AUTH
];
}
app()->make(RelevanceRepository::class)->insertAll($inserts);
return $type;
});
}
public function update(int $id, array $data)
{
return Db::transaction(function () use ($id, $data) {
$auth = array_filter(array_unique($data['auth']));
unset($data['auth']);
$inserts = [];
foreach ($auth as $aid) {
$inserts[] = [
'left_id' => $id,
'right_id' => (int)$aid,
'type' => RelevanceRepository::TYPE_MERCHANT_AUTH
];
}
$data['update_time'] = date('Y-m-d H:i:s',time());
$this->dao->update($id, $data);
$make = app()->make(RelevanceRepository::class);
$make->batchDelete($id, RelevanceRepository::TYPE_MERCHANT_AUTH);
$make->insertAll($inserts);
//更新未交保证金的商户
app()->make(SupplyRepository::class)->updateMargin($id, $data['margin'], $data['is_margin']);
});
}
public function markForm($id)
{
$data = $this->dao->get($id);
if (!$data) throw new ValidateException('数据不存在');
$form = Elm::createForm(Route::buildUrl('systemMerchantTypeMark', ['id' => $id])->build());
$form->setRule([
Elm::text('mark', '备注:', $data['mark'])->placeholder('请输入备注')->required(),
]);
return $form->setTitle('修改备注');
}
public function mark($id, $data)
{
if (!$this->dao->getWhereCount([$this->dao->getPk() => $id]))
throw new ValidateException('数据不存在');
$this->dao->update($id, $data);
}
public function detail($id)
{
$find = $this->dao->search(['mer_type_id' => $id])->with(['auth'])->find()->append(['merchant_count']);
if (!$find) throw new ValidateException('数据不存在');
$ids = array_column($find['auth']->toArray(), 'right_id');
unset($find['auth']);
$find['auth_ids'] = $ids;
$options = [];
if ($ids) {
$paths = app()->make(MenuRepository::class)->getAllOptions(1, true,compact('ids'),'path');
foreach ($paths as $id => $path) {
$ids = array_merge($ids, explode('/', trim($path, '/')));
array_push($ids, $id);
}
$auth = app()->make(MenuRepository::class)->getAllOptions(1, true, compact('ids'));
$options = formatTree($auth, 'menu_name');
}
$find['options'] = $options;
return $find;
}
}

View File

@ -0,0 +1,238 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\admin\system\supply;
use app\common\repositories\store\ExcelRepository;
use app\common\repositories\system\supply\FinancialRecordRepository;
use app\common\repositories\system\supply\SupplyRepository;
use crmeb\basic\BaseController;
use crmeb\services\ExcelService;
use think\App;
class FinancialRecord extends BaseController
{
protected $repository;
public function __construct(App $app, FinancialRecordRepository $repository)
{
parent::__construct($app);
$this->repository = $repository;
}
public function lst()
{
[$page, $limit] = $this->getPage();
$where = $this->request->params(['keyword', 'date', 'mer_id']);
$merId = $this->request->merId();
if ($merId) {
$where['mer_id'] = $merId;
$where['financial_type'] = ['order', 'mer_accoubts', 'brokerage_one', 'brokerage_two', 'refund_brokerage_one', 'refund_brokerage_two', 'refund_order', 'order_platform_coupon', 'order_svip_coupon', 'svip'];
} else {
$where['financial_type'] = ['order', 'sys_accoubts', 'brokerage_one', 'brokerage_two', 'refund_brokerage_one', 'refund_brokerage_two', 'refund_order', 'order_platform_coupon', 'order_svip_coupon', 'svip'];
}
return app('json')->success($this->repository->getList($where, $page, $limit));
}
public function export()
{
$where = $this->request->params(['keyword', 'date', 'mer_id']);
$merId = $this->request->merId();
if ($merId) {
$where['mer_id'] = $merId;
$where['financial_type'] = ['order', 'mer_accoubts', 'brokerage_one', 'brokerage_two', 'refund_brokerage_one', 'refund_brokerage_two', 'refund_order', 'order_platform_coupon', 'order_svip_coupon', 'svip'];
} else {
$where['financial_type'] = ['order', 'sys_accoubts', 'brokerage_one', 'brokerage_two', 'refund_brokerage_one', 'refund_brokerage_two', 'refund_order', 'order_platform_coupon', 'order_svip_coupon', 'svip'];
}
[$page, $limit] = $this->getPage();
$data = app()->make(ExcelService::class)->financial($where, $page, $limit);
return app('json')->success($data);
}
/**
* TODO 头部统计
* @return \think\response\Json
* @author Qinii
* @day 3/23/21
*/
public function getTitle()
{
$where = $this->request->params(['date']);
$where['is_mer'] = $this->request->merId() ?? 0;
if ($where['is_mer'] == 0) {
$data = $this->repository->getAdminTitle($where);
} else {
$data = $this->repository->getMerchantTitle($where);
}
return app('json')->success($data);
}
/**
* TODO 账单管理列表
* @return \think\response\Json
* @author Qinii
* @day 3/23/21
*/
public function getList()
{
[$page, $limit] = $this->getPage();
$where = $this->request->params([['type', 1], 'date']);
$where['is_mer'] = $this->request->merId() ?? 0;
$data = $this->repository->getAdminList($where, $page, $limit);
return app('json')->success($data);
}
/**
* TODO 详情
* @param $type
* @return \think\response\Json
* @author Qinii
* @day 3/23/21
*/
public function detail($type)
{
$date = $this->request->param('date');
$where['date'] = empty($date) ? date('Y-m-d', time()) : $date;
$where['is_mer'] = $this->request->merId() ?? 0;
if ($this->request->merId()) {
$data = $this->repository->merDetail($type, $where);
} else {
$data = $this->repository->adminDetail($type, $where);
}
return app('json')->success($data);
}
/**
* TODO 导出文件
* @param $type
* @author Qinii
* @day 3/25/21
*/
public function exportDetail($type)
{
[$page, $limit] = $this->getPage();
$date = $this->request->param('date');
$where['date'] = empty($date) ? date('Y-m-d', time()) : $date;
$where['type'] = $type;
$where['is_mer'] = $this->request->merId() ?? 0;
$data = app()->make(ExcelService::class)->exportFinancial($where, $page, $limit);
// app()->make(ExcelRepository::class)->create($where, $this->request->adminId(), 'exportFinancial',$where['is_mer']);
return app('json')->success($data);
}
/**
* TODO 流水统计
* @return \think\response\Json
* @author Qinii
* @day 5/7/21
*/
public function title()
{
$where = $this->request->params(['date']);
// $data = $this->repository->getFiniancialTitle($this->request->merId(),$where);
$data = [];
return app('json')->success($data);
}
/**
* 平台财务查看每个商户的财务信息列表
* @return \think\response\Json
* @author Qinii
* @day 2023/10/18
*
*/
public function supplyFinancial()
{
[$page, $limit] = $this->getPage();
$where = $this->request->params(['mer_id']);
$where['is_del'] = 0;
$data = $this->repository->merchantFinancial($where,$page,$limit);
return app('json')->success($data);
}
/**
* 财务记录
* @param $id
* @return \think\response\Json
* @author Qinii
* @day 2023/10/18
*/
public function merAcountsList($id)
{
[$page, $limit] = $this->getPage();
$where = $this->request->params([['type', 1], 'date']);
$where['is_mer'] = $id;
$data = $this->repository->getAdminList($where, $page, $limit);
return app('json')->success($data);
}
/**
* 头部统计
* @param $id
* @return \think\response\Json
* @author Qinii
* @day 2023/10/18
*/
public function merAcountsTitle($id)
{
$where = $this->request->params(['date']);
$where['is_mer'] = $id;
$data = $this->repository->getMerchantTitle($where);
return app('json')->success($data);
}
/**
* 详情
* @param $type
* @return \think\response\Json
* @author Qinii
* @day 2023/10/18
*/
public function merDetail($type)
{
$date = $this->request->param('date');
$where['date'] = empty($date) ? date('Y-m-d', time()) : $date;
$where['is_mer'] = $this->request->param('mer_id');
if (!$where['is_mer']) return app('json')->fail('请选择商户');
$data = $this->repository->merDetail($type, $where);
return app('json')->success($data);
}
/**
* 导出
* @param $type
* @return \think\response\Json
* @author Qinii
* @day 2023/10/18
*/
public function merExportDetail($type)
{
[$page, $limit] = $this->getPage();
$date = $this->request->param('date');
$where['date'] = empty($date) ? date('Y-m-d', time()) : $date;
$where['type'] = $type;
$where['is_mer'] = $this->request->param('mer_id');
if (!$where['is_mer']) return app('json')->fail('请选择商户');
$data = app()->make(ExcelService::class)->exportFinancial($where, $page, $limit);
return app('json')->success($data);
}
}

View File

@ -0,0 +1,381 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\admin\system\supply;
use app\common\repositories\store\product\ProductCopyRepository;
use app\common\repositories\store\service\StoreServiceRepository;
use app\common\repositories\system\operate\OperateLogRepository;
use crmeb\basic\BaseController;
use app\common\repositories\system\supply\SupplyAdminRepository;
use app\common\repositories\system\supply\SupplyCategoryRepository;
use app\common\repositories\system\supply\SupplyRepository;
use app\validate\admin\SupplyValidate;
use crmeb\jobs\ChangeSupplyStatusJob;
use FormBuilder\Exception\FormBuilderException;
use think\App;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Queue;
/**
* Class Supply
* @package app\controller\admin\system\supply
* @author xaboy
* @day 2020-04-16
*/
class Supply extends BaseController
{
/**
* @var SupplyRepository
*/
protected $repository;
/**
* Supply constructor.
* @param App $app
* @param SupplyRepository $repository
*/
public function __construct(App $app, SupplyRepository $repository)
{
parent::__construct($app);
$this->repository = $repository;
}
public function count()
{
$where = $this->request->params(['keyword', 'date', 'status', 'statusTag', 'is_trader', 'category_id', 'type_id']);
return app('json')->success($this->repository->count($where));
}
/**
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-04-16
*/
public function lst()
{
[$page, $limit] = $this->getPage();
$where = $this->request->params(['keyword', 'date', 'status', 'statusTag', 'is_trader', 'category_id', 'type_id', ['order', 'create_time'], 'is_best']);
return app('json')->success($this->repository->lst($where, $page, $limit));
}
/**
* @return mixed
* @throws FormBuilderException
* @author xaboy
* @day 2020-04-16
*/
public function createForm()
{
return app('json')->success(formToData($this->repository->form()));
}
/**
* @param SupplyValidate $validate
* @param SupplyCategoryRepository $SupplyCategoryRepository
* @param SupplyAdminRepository $adminRepository
* @return mixed
* @author xaboy
* @day 2020/7/2
*/
public function create(SupplyValidate $validate)
{
$data = $this->checkParam($validate);
$data['admin_info'] = $this->request->adminInfo();
$this->repository->createMerchant($data);
return app('json')->success('添加成功');
}
/**
* @param int $id
* @return mixed
* @throws FormBuilderException
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-04-16
*/
public function updateForm($id)
{
if (!$this->repository->exists($id))
return app('json')->fail('数据不存在');
return app('json')->success(formToData($this->repository->updateForm($id)));
}
/**
* @param int $id
* @param SupplyValidate $validate
* @param SupplyCategoryRepository $SupplyCategoryRepository
* @return mixed
* @throws DbException
* @author xaboy
* @day 2020-05-06
*/
public function update($id, SupplyValidate $validate, SupplyCategoryRepository $SupplyCategoryRepository)
{
$data = $this->checkParam($validate, true);
if (!$merchant = $this->repository->get($id))
return app('json')->fail('数据不存在');
if ($this->repository->fieldExists('mer_name', $data['mer_name'], $id))
return app('json')->fail('商户名已存在');
if ($data['mer_phone'] && isPhone($data['mer_phone']))
return app('json')->fail('请输入正确的手机号');
if (!$data['category_id'] || !$SupplyCategoryRepository->exists($data['category_id']))
return app('json')->fail('商户分类不存在');
unset($data['mer_account'], $data['mer_password']);
$margin = $this->repository->checkMargin($id, $data['type_id']);
$data['margin'] = $margin['margin'];
$data['is_margin'] = $margin['is_margin'];
$data['ot_margin'] = $margin['ot_margin'];
// 商户编辑记录日志
event('create_operate_log', [
'category' => OperateLogRepository::PLATFORM_EDIT_MERCHANT,
'data' => [
'merchant' => $merchant,
'admin_info' => $this->request->adminInfo(),
'update_infos' => $data
],
]);
$this->repository->update($id, $data);
return app('json')->success('编辑成功');
}
/**
* TODO
* @param $id
* @return \think\response\Json
* @author Qinii
* @day 2023/5/9
*/
public function deleteForm($id)
{
return app('json')->success(formToData($this->repository->deleteForm($id)));
}
/**
* @param int $id
* @return mixed
* @throws DbException
* @author xaboy
* @day 2020-04-17
*/
public function delete($id)
{
$type = $this->request->param('type', 0);
if (!$merchant = $this->repository->get(intval($id)))
return app('json')->fail('数据不存在');
if ($merchant->status)
return app('json')->fail('请先关闭该商户');
$this->repository->delete($id);
if ($type) $this->repository->clearAttachment($id);
return app('json')->success('删除成功');
}
/**
* @param SupplyValidate $validate
* @param bool $isUpdate
* @return array
* @author xaboy
* @day 2020-04-17
*/
public function checkParam(SupplyValidate $validate, $isUpdate = false)
{
$data = $this->request->params([['category_id', 0], ['type_id', 0], 'mer_name', 'commission_rate', 'real_name', 'mer_phone', 'mer_keyword', 'mer_address', 'mark', ['sort', 0], ['status', 0], ['is_audit', 0], ['is_best', 0], ['is_bro_goods', 0], ['is_bro_room', 0], ['is_trader', 0], 'sub_mchid', ['commission_switch', 0]]);
if (!$isUpdate) {
$data += $this->request->params(['mer_account', 'mer_password']);
} else {
$validate->isUpdate();
}
$validate->check($data);
return $data;
}
/**
* @param int $id
* @return mixed
* @throws DbException
* @author xaboy
* @day 2020-03-31
*/
public function switchStatus($id)
{
$is_best = $this->request->param('status', 0) == 1 ? 1 : 0;
if (!$this->repository->exists($id))
return app('json')->fail('数据不存在');
$this->repository->update($id, compact('is_best'));
return app('json')->success('修改成功');
}
/**
* @param int $id
* @return mixed
* @throws DbException
* @author xaboy
* @day 2020-03-31
*/
public function switchClose($id)
{
$status = $this->request->param('status', 0) == 1 ? 1 : 0;
if (!$merchant = $this->repository->get($id))
return app('json')->fail('数据不存在');
$this->repository->update($id, compact('status'));
app()->make(StoreServiceRepository::class)->close($id, 'mer_id');
Queue::push(ChangeSupplyStatusJob::class, $id);
// 商户编辑记录日志
event('create_operate_log', [
'category' => OperateLogRepository::PLATFORM_EDIT_MERCHANT_AUDIT_STATUS,
'data' => [
'merchant' => $merchant,
'admin_info' => $this->request->adminInfo(),
'update_infos' => ['status' => $status]
],
]);
return app('json')->success('修改成功');
}
/**
* @param $id
* @param SupplyAdminRepository $adminRepository
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020/7/7
*/
public function login($id, SupplyAdminRepository $adminRepository)
{
if (!$this->repository->exists($id))
return app('json')->fail('数据不存在');
$adminInfo = $adminRepository->merIdByAdmin($id);
$tokenInfo = $adminRepository->createToken($adminInfo);
$admin = $adminInfo->toArray();
unset($admin['pwd']);
$data = [
'token' => $tokenInfo['token'],
'exp' => $tokenInfo['out'],
'admin' => $admin,
'url' => '/' . config('admin.merchant_prefix')
];
return app('json')->success($data);
}
/**
* TODO 修改复制次数表单
* @param $id
* @return mixed
* @author Qinii
* @day 2020-08-06
*/
public function changeCopyNumForm($id)
{
return app('json')->success(formToData($this->repository->copyForm($id)));
}
/**
* TODO 修改复制次数
* @param $id
* @return mixed
* @author Qinii
* @day 2020-08-06
*/
public function changeCopyNum($id)
{
$data = $this->request->params(['type', 'num']);
$num = $data['num'];
if ($num <= 0) return app('json')->fail('次数必须为正整数');
if ($data['type'] == 2) {
$mer_num = $this->repository->getCopyNum($id);
if (($mer_num - $num) < 0) return app('json')->fail('剩余次数不足');
$num = '-' . $data['num'];
}
$arr = [
'type' => 'sys',
'num' => $num,
'message' => '平台修改「' . $this->request->adminId() . '」',
];
app()->make(ProductCopyRepository::class)->add($arr, $id);
return app('json')->success('修改成功');
}
/**
* TODO 清理删除的商户内容
* @return \think\response\Json
* @author Qinii
* @day 5/15/21
*/
public function clearRedundancy()
{
$this->repository->clearRedundancy();
return app('json')->success('清除完成');
}
public function makeUpMarginLst()
{
[$page, $limit] = $this->getPage();
$where['margin'] = 0;
$data = $this->repository->lst($where, $page, $limit);
return app('json')->success($data);
}
/**
* TODO 平台后台商户详情
* @param $id
* @return \think\response\Json
* @author Qinii
* @day 2023/7/1
*/
public function detail($id)
{
$data = $this->repository->adminDetail($id);
return app('json')->success($data);
}
/**
* 商户操作记录
* @param $product_id
* @return \think\response\Json
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*
* @date 2023/10/19
* @author yyw
*/
public function getOperateList($merchant_id)
{
$where = $this->request->params([
['type', ''],
['date', '']
]);
$where['relevance_id'] = $merchant_id;
$where['relevance_type'] = OperateLogRepository::RELEVANCE_MERCHANT;
[$page, $limit] = $this->getPage();
return app('json')->success(app()->make(OperateLogRepository::class)->lst($where, $page, $limit));
}
}

View File

@ -0,0 +1,85 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\admin\system\supply;
use crmeb\basic\BaseController;
use app\common\repositories\system\supply\SupplyAdminRepository;
use app\validate\admin\AdminValidate;
use FormBuilder\Exception\FormBuilderException;
use think\App;
use think\db\exception\DbException;
/**
* Class SupplyAdmin
* @package app\controller\admin\system\supply
* @author xaboy
* @day 2020-04-17
*/
class SupplyAdmin extends BaseController
{
/**
* @var SupplyAdminRepository
*/
protected $repository;
/**
* SupplyAdmin constructor.
* @param App $app
* @param SupplyAdminRepository $repository
*/
public function __construct(App $app, SupplyAdminRepository $repository)
{
parent::__construct($app);
$this->repository = $repository;
}
/**
* @param int $id
* @return mixed
* @throws FormBuilderException
* @author xaboy
* @day 2020-04-17
*/
public function passwordForm($id)
{
return app('json')->success(formToData($this->repository->passwordForm($id, 1)));
}
/**
* @param int $id
* @param AdminValidate $validate
* @return mixed
* @throws DbException
* @author xaboy
* @day 2020-04-17
*/
public function password($id, AdminValidate $validate)
{
$data = $this->request->params(['pwd', 'againPassword']);
$validate->isPassword()->check($data);
if ($data['pwd'] !== $data['againPassword'])
return app('json')->fail('两次密码输入不一致');
$adminId = $this->repository->merchantIdByTopAdminId($id);
if (!$adminId)
return app('json')->fail('商户不存在');
$data['pwd'] = $this->repository->passwordEncode($data['pwd']);
unset($data['againPassword']);
$this->repository->update($adminId, $data);
return app('json')->success('修改密码成功');
}
}

View File

@ -0,0 +1,79 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\admin\system\supply;
use think\App;
use crmeb\basic\BaseController;
use app\common\repositories\system\supply\SupplyApplymentsRepository;
class SupplyApplyments extends BaseController
{
protected $repository;
/**
* SupplyApplyments constructor.
* @param App $app
* @param SupplyApplymentsRepository $repository
*/
public function __construct(App $app, SupplyApplymentsRepository $repository)
{
parent::__construct($app);
$this->repository = $repository;
}
public function lst()
{
[$page, $limit] = $this->getPage();
$where = $this->request->params(['mer_name', 'status', 'date', 'mer_applyments_id', 'out_request_no', 'applyment_id', 'mer_id']);
return app('json')->success($this->repository->getList($where, $page, $limit));
}
public function detail($id)
{
$data = $this->repository->detail($id);
if (empty($data)) return app('json')->fail('数据不存在');
return app('json')->success($data);
}
public function switchWithStatus($id)
{
$data = $this->request->params(['status', 'message']);
if (!in_array($data['status'], [0, -1, 10])) return app('json')->fail('参数错误');
if ($data['status'] == -1 && !$data['message']) return app('json')->fail('驳回理由为空');
$this->repository->switchWithStatus($id, $data);
return app('json')->success('审核成功');
}
public function getSupply($id)
{
$data = $this->repository->getMerchant($id);
return app('json')->success($data);
}
public function markForm($id)
{
return app('json')->success(formToData($this->repository->markForm($id)));
}
public function mark($id)
{
if (!$this->repository->get($id))
return app('json')->fail('数据不存在');
$this->repository->update($id, ['mark' => $this->request->param('mark', '')]);
return app('json')->success('备注成功');
}
}

View File

@ -0,0 +1,161 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\admin\system\supply;
use crmeb\basic\BaseController;
use app\common\repositories\system\supply\SupplyCategoryRepository;
use app\common\repositories\system\supply\SupplyRepository;
use app\validate\admin\SupplyCategoryValidate;
use FormBuilder\Exception\FormBuilderException;
use think\App;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/**
* Class SupplyCategory
* @package app\controller\admin\system\supply
* @author xaboy
* @day 2020-05-06
*/
class SupplyCategory extends BaseController
{
/**
* @var SupplyCategoryRepository
*/
protected $repository;
/**
* SupplyCategory constructor.
* @param App $app
* @param SupplyCategoryRepository $repository
*/
public function __construct(App $app, SupplyCategoryRepository $repository)
{
parent::__construct($app);
$this->repository = $repository;
}
/**
* @return mixed
* @throws DbException
* @throws DataNotFoundException
* @throws ModelNotFoundException
* @author xaboy
* @day 2020-05-06
*/
public function lst()
{
[$page, $limit] = $this->getPage();
return app('json')->success($this->repository->getList([], $page, $limit));
}
public function getOptions()
{
return app('json')->success($this->repository->allOptions());
}
/**
* @param SupplyCategoryValidate $validate
* @return mixed
* @author xaboy
* @day 2020-05-06
*/
public function create(SupplyCategoryValidate $validate)
{
$data = $this->checkParams($validate);
$data['commission_rate'] = bcdiv($data['commission_rate'], 100, 4);
$this->repository->create($data);
return app('json')->success('添加成功');
}
/**
* @return mixed
* @throws FormBuilderException
* @author xaboy
* @day 2020-05-06
*/
public function createForm()
{
return app('json')->success(formToData($this->repository->form()));
}
/**
* @param $id
* @param SupplyCategoryValidate $validate
* @return mixed
* @throws DbException
* @author xaboy
* @day 2020-05-06
*/
public function update($id, SupplyCategoryValidate $validate)
{
$data = $this->checkParams($validate);
if (!$this->repository->exists($id))
return app('json')->fail('数据不存在');
$data['commission_rate'] = bcdiv($data['commission_rate'], 100, 4);
$this->repository->update($id, $data);
return app('json')->success('编辑成功');
}
/**
* @param $id
* @return mixed
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws FormBuilderException
* @author xaboy
* @day 2020-05-06
*/
public function updateForm($id)
{
if (!$this->repository->exists($id))
return app('json')->fail('数据不存在');
return app('json')->success(formToData($this->repository->updateForm($id)));
}
/**
* @param $id
* @param SupplyRepository $SupplyRepository
* @return mixed
* @throws DbException
* @author xaboy
* @day 2020-05-06
*/
public function delete($id, SupplyRepository $SupplyRepository)
{
if (!$this->repository->exists($id))
return app('json')->fail('数据不存在');
if ($SupplyRepository->fieldExists('category_id', $id))
return app('json')->fail('存在商户,无法删除');
$this->repository->delete($id);
return app('json')->success('删除成功');
}
/**
* @param SupplyCategoryValidate $validate
* @return array
* @author xaboy
* @day 2020-05-06
*/
public function checkParams(SupplyCategoryValidate $validate)
{
$data = $this->request->params(['category_name', ['commission_rate', 0]]);
$validate->check($data);
return $data;
}
}

View File

@ -0,0 +1,118 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\admin\system\supply;
use app\common\repositories\system\CacheRepository;
use crmeb\services\ExcelService;
use think\App;
use crmeb\basic\BaseController;
use app\common\repositories\system\supply\SupplyIntentionRepository;
class SupplyIntention extends BaseController
{
protected $repository;
/**
* SupplyIntention constructor.
* @param App $app
* @param SupplyIntentionRepository $repository
*/
public function __construct(App $app, SupplyIntentionRepository $repository)
{
parent::__construct($app);
$this->repository = $repository;
}
public function lst()
{
[$page, $limit] = $this->getPage();
$where = $this->request->params(['mer_name', 'status', 'date', 'keyword', 'mer_intention_id', 'category_id', 'type_id']);
return app('json')->success($this->repository->getList($where, $page, $limit));
}
public function form($id)
{
if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
return app('json')->fail('数据不存在');
return app('json')->success(formToData($this->repository->markForm($id)));
}
public function statusForm($id)
{
if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
return app('json')->fail('数据不存在');
return app('json')->success(formToData($this->repository->statusForm($id)));
}
public function mark($id)
{
if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
return app('json')->fail('数据不存在');
$data = $this->request->param('mark');
$this->repository->update($id, ['mark' => $data]);
return app('json')->success('修改成功');
}
public function switchStatus($id)
{
if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
return app('json')->fail('数据不存在');
$data = $this->request->params(['status', 'fail_msg', 'create_mer']);
$data['status'] = $data['status'] == 1 ? 1 : 2;
$this->repository->updateStatus($id, $data);
return app('json')->success('修改成功');
}
public function delete($id)
{
if (!$this->repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0]))
return app('json')->fail('数据不存在');
$this->repository->update($id, ['is_del' => 1]);
return app('json')->success('删除成功');
}
/**
* @Author:Qinii
* @Date: 2020/9/15
* @return mixed
*/
public function saveAgree()
{
$agree = $this->request->param('agree');
app()->make(CacheRepository::class)->save('sys_intention_agree', $agree);
return app('json')->success('保存成功');
}
/**
* @Author:Qinii
* @Date: 2020/9/15
* @return mixed
*/
public function getAgree()
{
$make = app()->make(CacheRepository::class);
return app('json')->success(['sys_intention_agree' => $make->getResult('sys_intention_agree')]);
}
public function excel()
{
$where = $this->request->params(['mer_name', 'status', 'date', 'keyword', 'mer_intention_id', 'category_id', 'type_id']);
[$page, $limit] = $this->getPage();
$data = app()->make(ExcelService::class)->intention($where, $page, $limit);
return app('json')->success($data);
}
}

View File

@ -0,0 +1,96 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\admin\system\supply;
use app\common\repositories\system\supply\SupplyRepository;
use app\common\repositories\system\serve\ServeOrderRepository;
use app\common\repositories\user\UserBillRepository;
use crmeb\basic\BaseController;
use think\App;
class SupplyMargin extends BaseController
{
/**
* SupplyMargin constructor.
* @param App $app
*/
public function __construct(App $app)
{
parent::__construct($app);
}
/**
* TODO
* @param ServeOrderRepository $orderRepository
* @return \think\response\Json
* @author Qinii
* @day 1/26/22
*/
public function lst(SupplyRepository $orderRepository)
{
[$page, $limit] = $this->getPage();
$where = $this->request->params(['date', 'keyword', 'is_trader', 'category_id', 'type_id']);
$where['margin'] = 10;
$data = $orderRepository->getPaidToMarginLst($where, $page, $limit);
return app('json')->success($data);
}
public function getMarginLst($id)
{
[$page, $limit] = $this->getPage();
$where = [
'mer_id' => $id,
'category' => 'mer_margin'
];
$data = app()->make(UserBillRepository::class)->getLst($where, $page, $limit);
return app('json')->success($data);
}
/**
* TODO 扣除保证金
* @param $id
* @return \think\response\Json
* @author Qinii
* @day 2023/4/25
*/
public function setMarginForm($id)
{
$data = app()->make(SupplyRepository::class)->setMarginForm($id);
return app('json')->success(formToData($data));
}
public function setMargin()
{
$data = $this->request->params(['mer_id', 'number', ['type', 'mer_margin'], 'mark']);
$data['title'] = '保证金扣除';
if ($data['number'] < 0)
return app('json')->fail('扣除金额不能小于0');
app()->make(SupplyRepository::class)->setMargin($data);
return app('json')->success('扣除保证金成功');
}
public function localMarginForm($id)
{
$data = app()->make(SupplyRepository::class)->localMarginForm($id);
return app('json')->success(formToData($data));
}
public function localMarginSet($id)
{
$data = $this->request->params(['number', 'mark', 'status']);
app()->make(SupplyRepository::class)->localMarginSet($id, $data);
return app('json')->success('操作成功');
}
}

View File

@ -0,0 +1,107 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\admin\system\supply;
use app\common\repositories\system\auth\MenuRepository;
use app\common\repositories\system\supply\SupplyTypeRepository;
use app\validate\admin\SupplyTypeValidate;
use crmeb\basic\BaseController;
use think\App;
use think\exception\ValidateException;
class SupplyType extends BaseController
{
protected $repository;
public function __construct(App $app, SupplyTypeRepository $repository)
{
parent::__construct($app);
$this->repository = $repository;
}
public function lst()
{
[$page, $limit] = $this->getPage();
return app('json')->success($this->repository->getList($page, $limit));
}
public function options()
{
return app('json')->success($this->repository->getOptions());
}
public function create()
{
$this->repository->create($this->getValidParams());
return app('json')->success('添加成功');
}
public function update($id)
{
if (!$merchant_type = $this->repository->get($id)) {
return app('json')->fail('数据不存在');
}
$data = $this->getValidParams();
$this->repository->update($id, $data);
return app('json')->success('修改成功');
}
public function detail($id)
{
$data = $this->repository->detail($id);
return app('json')->success($data);
}
public function markForm($id)
{
return app('json')->success(formToData($this->repository->markForm($id)));
}
public function mark($id)
{
$this->repository->mark($id, $this->request->params(['mark']));
return app('json')->success('修改成功');
}
public function delete($id)
{
if (!$this->repository->exists($id)) {
return app('json')->fail('数据不存在');
}
$this->repository->delete($id);
return app('json')->success('删除成功');
}
public function mer_auth()
{
$options = app()->make(MenuRepository::class)->getAllOptions(1);
return app('json')->success(formatTree($options, 'menu_name'));
}
protected function getValidParams()
{
$data = $this->request->params(['type_name', 'type_info', 'is_margin', 'margin', 'auth', 'description', 'mark']);
$validate = app()->make(SupplyTypeValidate::class);
$validate->check($data);
if ($data['is_margin'] == 1) {
if ($data['margin'] <= 0) throw new ValidateException('保证金必须大于0');
} else {
$data['margin'] = 0;
}
return $data;
}
}

View File

@ -0,0 +1,27 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\validate\admin;
use think\Validate;
class SupplyCategoryValidate extends Validate
{
protected $failException = true;
protected $rule = [
'category_name|分类名称' => 'require|max:32',
'commission_rate|手续费' => 'require|float|>=:0|<=:100'
];
}

View File

@ -0,0 +1,30 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\validate\admin;
use think\Validate;
class SupplyTypeValidate extends Validate
{
protected $failException = true;
protected $rule = [
'type_name|店铺类型名称' => 'require|max:5',
'type_info|店铺类型要求' => 'max:256',
'is_margin|是否有保证金' => 'require|in:0,1',
'auth|权限' => 'require|array|min:1',
'margin|保证金(¥)' => 'requireIf:is_margin,1',
'description|其他说明' => 'max:256',
];
}

View File

@ -0,0 +1,66 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\validate\admin;
use think\Validate;
/**
* Class MerchantValidate
* @package app\validate\admin
* @author xaboy
* @day 2020-04-17
*/
class SupplyValidate extends Validate
{
/**
* @var bool
*/
protected $failException = true;
/**
* @var array
*/
protected $rule = [
'category_id|商户分类' => 'require',
'type_id|店铺类型' => 'integer',
'mer_name|商户名称' => 'require|max:32',
'mer_account|商户账号' => 'require|alphaNum|min:4|max:16',
'mer_password|商户密码' => 'require|min:4|max:16',
'real_name|商户姓名' => 'max:16',
'mer_phone|商户手机号' => 'require',
'sort|排序' => 'require',
'mer_keyword|商户关键字' => 'max:64',
'mer_address|商户地址' => 'max:64',
'mark|备注' => 'max:64',
'status|开启状态' => 'require|in:0,1',
'is_audit|产品审核状态' => 'require|in:0,1',
'is_best|推荐状态' => 'require|in:0,1',
'is_bro_goods|直播商品状态' => 'require|in:0,1',
'is_bro_room|直播间状态' => 'require|in:0,1',
'is_trader|自营状态' => 'require|in:0,1',
'commission_rate|提成比例' => '>=:0'
];
/**
* @return $this
* @author xaboy
* @day 2020-04-17
*/
public function isUpdate()
{
unset($this->rule['mer_account|商户账号'], $this->rule['mer_password|商户密码']);
return $this;
}
}

View File

@ -1 +1 @@
TQNLoFxalS7DUihukQpHQmmPW2I4HGrUBPgv33n+CtR3TK1UVTswRz8VPLoB/1jpxedvnMipu2Hx194y3cwWWKrOkEF/gBCDE20kWdiwAHTPLDXDiY9ORWLUR6EDoeGQWdcrcJAoptSi7ntAqqcVYQgncQSEPY4Ukuox6US5AmY=,00000000
CcsBxrXbu1K+J7wRAkymRO1nFyKDCCP3Mh3QrgwgqdThSRhkqqWzvcLRa0U0/13f1/EQDXoAxLy3s8DhpbmY2lAzoF3hCL+8QhWmAL/GaWfCWxDPgi2o1C1D5Ku6oIZY/Gm9ZPhADBlLEZ/4hFShnraULur3YAdXopRr1KkNXRgdL6ULP54tPhdlDtub5o7C8I0ningyRdEbMrTfq56oqW9qjMXrQzrPGodiQwOzgvb7SdeEz+FbSwp87yUPs15IvfnvCvhCnTBqITHU6Fao/Ck/rUs2JPj99c94ohioSiT2gYDrFddq4xXPprxb8Op5PVxY+i5QC4P4Q00yRJ8/CA==,

View File

@ -0,0 +1,43 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace crmeb\jobs;
use app\common\repositories\store\product\ProductRepository;
use app\common\repositories\store\service\StoreServiceRepository;
use app\common\repositories\system\supply\SupplyRepository;
use crmeb\interfaces\JobInterface;
use think\facade\Log;
use think\queue\Job;
class ChangeSupplyStatusJob implements JobInterface
{
public function fire($job, $merId)
{
$merchant = app()->make(SupplyRepository::class)->get($merId);
if ($merchant) {
$where = [
'mer_status' => ($merchant['is_del'] || !$merchant['mer_state'] || !$merchant['status']) ? 0 : 1
];
app()->make(ProductRepository::class)->changeMerchantProduct($merId, $where);
}
$job->delete();
}
public function failed($data)
{
// TODO: Implement failed() method.
}
}

View File

@ -0,0 +1,89 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace crmeb\jobs;
use app\common\repositories\store\coupon\StoreCouponRepository;
use app\common\repositories\store\coupon\StoreCouponUserRepository;
use app\common\repositories\store\GuaranteeTemplateRepository;
use app\common\repositories\store\GuaranteeValueRepository;
use app\common\repositories\store\parameter\ParameterRepository;
use app\common\repositories\store\parameter\ParameterTemplateRepository;
use app\common\repositories\store\parameter\ParameterValueRepository;
use app\common\repositories\store\product\ProductCateRepository;
use app\common\repositories\store\product\ProductLabelRepository;
use app\common\repositories\store\product\ProductReplyRepository;
use app\common\repositories\store\product\ProductRepository;
use app\common\repositories\store\product\StoreDiscountProductRepository;
use app\common\repositories\store\product\StoreDiscountRepository;
use app\common\repositories\store\shipping\ShippingTemplateRepository;
use app\common\repositories\store\StoreCategoryRepository;
use app\common\repositories\system\config\ConfigValueRepository;
use app\common\repositories\system\groupData\GroupDataRepository;
use crmeb\interfaces\JobInterface;
use think\facade\Log;
class ClearSupplyStoreJob implements JobInterface
{
public function fire($job, $data)
{
try{
/**
* 商户商品分类
* 商户商品
* 商品参数
* 商品服务模板
* 商品标签
* 商品评价
* 优惠套餐
* 运费模板
* 商户优惠券
* 商户组合数据
* 配置
* 商户图片及源文件
*/
$merId = (int)$data['mer_id'];
app()->make(ProductRepository::class)->clearMerchantProduct($merId);
$servers = [
app()->make(ProductCateRepository::class),
app()->make(StoreCategoryRepository::class),
app()->make(ParameterRepository::class),
app()->make(ParameterTemplateRepository::class),
app()->make(ParameterValueRepository::class),
app()->make(GuaranteeTemplateRepository::class),
app()->make(GuaranteeValueRepository::class),
app()->make(ProductLabelRepository::class),
app()->make(ProductReplyRepository::class),
app()->make(StoreDiscountRepository::class),
app()->make(StoreDiscountProductRepository::class),
app()->make(StoreCouponRepository::class),
app()->make(StoreCouponUserRepository::class),
app()->make(GroupDataRepository::class),
app()->make(ConfigValueRepository::class),
app()->make(ShippingTemplateRepository::class),
];
foreach ($servers as $server) {
$server->clear($merId,'mer_id');
}
}catch (\Exception $e){
Log::info('商户ID'.$data['mer_id'].'清除出错:'.$e->getMessage());
}
$job->delete();
}
public function failed($data)
{
// TODO: Implement failed() method.
}
}

View File

@ -21,7 +21,7 @@ Route::group(function () {
Route::group('system/menu', function () {
Route::get('lst', '/getList')->name('systemMenuGetLst')->option([
'_alias' => '平台菜单/权限列表',
]);
]);
Route::get('create/form', '/createForm')->name('systemMenuCreateForm')->option([
'_alias' => '平台菜单/权限添加表单',
'_auth' => false,
@ -34,13 +34,13 @@ Route::group(function () {
]);
Route::post('create', '/create')->name('systemMenuCreate')->option([
'_alias' => '平台菜单/权限添加',
]);
]);
Route::post('update/:id', '/update')->name('systemMenuUpdate')->option([
'_alias' => '平台菜单/权限编辑',
]);
]);
Route::delete('delete/:id', '/delete')->name('systemMenuDelete')->option([
'_alias' => '平台菜单/权限删除',
]);
]);
})->prefix('admin.system.auth.Menu')->option([
'_path' => '/setting/menu',
'_auth' => true,
@ -50,7 +50,7 @@ Route::group(function () {
Route::group('merchant/menu', function () {
Route::get('lst', '/getList')->name('systemMerchantMenuGetLst')->append(['merchant' => 1])->option([
'_alias' => '商户菜单/权限列表',
]);
]);
Route::get('create/form', '/createForm')->name('systemMerchantMenuCreateForm')->append(['merchant' => 1])->option([
'_alias' => '商户菜单/权限添加表单',
'_auth' => false,
@ -63,18 +63,46 @@ Route::group(function () {
]);
Route::post('create', '/create')->name('systemMerchantMenuCreate')->append(['merchant' => 1])->option([
'_alias' => '商户菜单/权限添加',
]);
]);
Route::post('update/:id', '/update')->name('systemMerchantMenuUpdate')->append(['merchant' => 1])->option([
'_alias' => '商户菜单/权限编辑',
]);
]);
Route::delete('delete/:id', '/delete')->name('systemMerchantMenuDelete')->append(['merchant' => 1])->option([
'_alias' => '商户菜单/权限删除',
]);
]);
})->prefix('admin.system.auth.Menu')->option([
'_path' => '/merchant/system',
'_auth' => true,
]);
//供销权限管理
Route::group('supply/menu', function () {
Route::get('lst', '/getList')->name('systemSupplyMenuGetLst')->append(['merchant' => 1])->option([
'_alias' => '商户菜单/权限列表',
]);
Route::get('create/form', '/createForm')->name('systemSupplyMenuCreateForm')->append(['merchant' => 1])->option([
'_alias' => '商户菜单/权限添加表单',
'_auth' => false,
'_form' => 'systemSupplyMenuCreate',
]);
Route::get('update/form/:id', '/updateForm')->name('systemSupplyMenuUpdateForm')->append(['merchant' => 1])->option([
'_alias' => '商户菜单/权限编辑表单',
'_auth' => false,
'_form' => 'systemSupplyMenuUpdate',
]);
Route::post('create', '/create')->name('systemSupplyMenuCreate')->append(['merchant' => 1])->option([
'_alias' => '商户菜单/权限添加',
]);
Route::post('update/:id', '/update')->name('systemSupplyMenuUpdate')->append(['merchant' => 1])->option([
'_alias' => '商户菜单/权限编辑',
]);
Route::delete('delete/:id', '/delete')->name('systemSupplyMenuDelete')->append(['merchant' => 1])->option([
'_alias' => '商户菜单/权限删除',
]);
})->prefix('admin.system.auth.Menu')->option([
'_path' => '/supply/system',
'_auth' => true,
]);
})->middleware(AllowOriginMiddleware::class)
->middleware(AdminTokenMiddleware::class, true)
->middleware(AdminAuthMiddleware::class)

273
route/admin/supply.php Normal file
View File

@ -0,0 +1,273 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
use think\facade\Route;
use app\common\middleware\AdminAuthMiddleware;
use app\common\middleware\AdminTokenMiddleware;
use app\common\middleware\AllowOriginMiddleware;
use app\common\middleware\LogMiddleware;
Route::group(function () {
//商户分类
Route::group('system/supply', function () {
Route::get('category/lst', '/lst')->name('systemSupplyCategoryLst')->option([
'_alias' => '商户分类列表',
]);
Route::get('category_lst', '/lst')->option([
'_alias' => '商户分类列表',
'_auth' => false,
]);
Route::post('category', '/create')->name('systemSupplyCategoryCreate')->option([
'_alias' => '商户分类添加',
]);
Route::get('category/form', '/createForm')->name('systemSupplyCategoryCreateForm')->option([
'_alias' => '商户分类添加表单',
'_auth' => false,
'_form' => 'systemSupplyCategoryCreate',
]);
Route::delete('category/:id', '/delete')->name('systemSupplyCategoryDelete')->option([
'_alias' => '商户分类删除',
]);
Route::post('category/:id', '/update')->name('systemSupplyCategoryUpdate')->option([
'_alias' => '商户分类编辑',
]);
Route::get('category/form/:id', '/updateForm')->name('systemSupplyCategoryUpdateForm')->option([
'_alias' => '商户分类编辑表单',
'_auth' => false,
'_form' => 'systemSupplyCategoryUpdate',
]);
Route::get('category/options', '/getOptions')->option([
'_alias' => '商户分类筛选',
'_auth' => false,
]);
})->prefix('admin.system.supply.SupplyCategory')->option([
'_path' => '/supply/classify',
'_auth' => true,
]);
//申请列表
Route::group('supply/intention', function () {
Route::get('lst', '/lst')->name('systemSupplyIntentionLst')->option([
'_alias' => '列表',
]);
Route::post('status/:id', '/switchStatus')->name('systemSupplyIntentionStatus')->option([
'_alias' => '审核',
]);
Route::delete('delete/:id', '/delete')->name('systemSupplyIntentionDelete')->option([
'_alias' => '删除',
]);
Route::get('mark/:id/form', '/form')->name('systemSupplyIntentionMarkForm')->option([
'_alias' => '备注',
'_auth' => false,
'_form' => 'systemSupplyIntentionMark',
]);
Route::get('status/:id/form', '/statusForm')->name('systemSupplyIntentionStatusForm')->option([
'_alias' => '申请商户',
'_auth' => false,
'_form' => 'systemSupplyIntentionStatus',
]);
Route::post('mark/:id', '/mark')->name('systemSupplyIntentionMark')->option([
'_alias' => '备注',
]);
Route::get('excel', '/excel');
})->prefix('admin.system.supply.SupplyIntention')->option([
'_path' => '/supply/application',
'_auth' => true,
]);
//商户管理
Route::group('system/supply', function () {
Route::get('create/form', '.Supply/createForm')->name('systemSupplyCreateForm')->option([
'_alias' => '商户列表',
]);
Route::get('count', '.Supply/count')->name('systemSupplyCount')->option([
'_alias' => '商户列表统计',
]);
Route::get('lst', '.Supply/lst')->name('systemSupplyLst')->option([
'_alias' => '商户列表',
]);
Route::post('create', '.Supply/create')->name('systemSupplyCreate')->option([
'_alias' => '商户添加',
]);
Route::get('update/form/:id', '.Supply/updateForm')->name('systemSupplyUpdateForm')->option([
'_alias' => '商户编辑表单',
'_auth' => false,
'_form' => 'systemSupplyUpdate',
]);
Route::post('update/:id', '.Supply/update')->name('systemSupplyUpdate')->option([
'_alias' => '商户编辑',
]);
Route::post('status/:id', '.Supply/switchStatus')->name('systemSupplyStatus')->option([
'_alias' => '商户修改推荐',
]);
Route::post('close/:id', '.Supply/switchClose')->name('systemSupplyClose')->option([
'_alias' => '商户开启/关闭',
]);
Route::get('delete/:id/form', '.Supply/deleteForm')->name('systemSupplyDeleteForm')->option([
'_alias' => '商户删除',
'_auth' => false,
'_form' => 'systemSupplyDelete',
]);
Route::post('delete/:id', '.Supply/delete')->name('systemSupplyDelete')->option([
'_alias' => '商户删除',
]);
Route::post('password/:id', '.SupplyAdmin/password')->name('systemSupplyAdminPassword')->option([
'_alias' => '商户修改密码',
]);
Route::get('password/form/:id', '.SupplyAdmin/passwordForm')->name('systemSupplyAdminPasswordForm')->option([
'_alias' => '商户修改密码表单',
'_auth' => false,
'_form' => 'systemSupplyAdminPassword',
]);
Route::post('login/:id', '.Supply/login')->name('systemSupplyLogin')->option([
'_alias' => '商户登录',
]);
Route::get('changecopy/:id/form', '.Supply/changeCopyNumForm')->name('systemSupplyChangeCopyForm')->option([
'_alias' => '修改采集商品次数表单',
'_auth' => false,
'_form' => 'systemSupplyChangeCopy',
]);
Route::post('changecopy/:id', '.Supply/changeCopyNum')->name('systemSupplyChangeCopy')->option([
'_alias' => '修改采集商品次数',
]);
Route::get('detail/:id', '.Supply/detail')->name('systemSupplyDetail')->option([
'_alias' => '详情',
]);
Route::get('get_operate_list/:merchant_id', '.Supply/getOperateList')->name('systemSupplyOperateList')->option([
'_alias' => '操作日志',
]);
})->prefix('admin.system.supply')->option([
'_path' => '/supply/list',
'_auth' => true,
'_append'=> [
[
'_name' =>'uploadImage',
'_path' =>'/supply/list',
'_alias' => '上传图片',
'_auth' => true,
],
[
'_name' =>'systemAttachmentLst',
'_path' =>'/supply/list',
'_alias' => '图片列表',
'_auth' => true,
],
]
]);
Route::group('supply/type', function () {
Route::get('lst', '/lst')->name('systemSupplyTypeLst')->option([
'_alias' => '列表',
]);
Route::post('create', '/create')->name('systemSupplyTypeCreate')->option([
'_alias' => '添加',
]);
Route::post('update/:id', '/update')->name('systemSupplyTypeUpdate')->option([
'_alias' => '编辑',
]);
Route::delete('delete/:id', '/delete')->name('systemSupplyTypeDelete')->option([
'_alias' => '删除',
]);
Route::get('mark/:id', '/markForm')->name('systemSupplyTypeMarkForm')->option([
'_alias' => '备注',
'_auth' => false,
'_form' => 'systemSupplyTypeMark',
]);
Route::post('mark/:id', '/mark')->name('systemSupplyTypeMark')->option([
'_alias' => '备注',
]);
Route::get('detail/:id', '/detail')->name('systemSupplyTypeDetail')->option([
'_alias' => '备注',
]);
Route::get('options', '/options')->option([
'_alias' => '筛选',
'_auth' => false,
]);
Route::get('mer_auth', '/mer_auth')->option([
'_alias' => '权限',
'_auth' => false,
]);
})->prefix('admin.system.supply.SupplyType')->option([
'_path' => '/supply/type',
'_auth' => true,
]);
//保证金
Route::group('margin', function () {
//缴纳记录
Route::get('lst', 'supply.SupplyMargin/lst')->name('systemSupplyMarginLst')->option([
'_alias' => '缴纳记录',
]);
//扣费记录
Route::get('list/:id', 'supply.SupplyMargin/getMarginLst')->name('systemMarginList')->option([
'_alias' => '扣费记录',
]);
//扣除保证金
Route::get('set/:id/form', 'supply.SupplyMargin/setMarginForm')->name('systemMarginSetForm')->option([
'_alias' => '扣除保证金表单',
'_auth' => false,
'_form' => 'systemMarginSet',
]);
Route::post('set', 'supply.SupplyMargin/setMargin')->name('systemMarginSet')->option([
'_alias' => '扣除保证金',
]);
//退款申请
Route::get('refund/lst', 'financial.Financial/getMarginLst')->name('systemMarginRefundList')->option([
'_alias' => '退款申请列表',
]);
Route::get('refund/show/:id', 'financial.Financial/refundShow')->name('systemMarginRefundShow')->option([
'_alias' => '退款申请详情',
]);
//审核
Route::get('refund/status/:id/form', 'financial.Financial/statusForm')->name('systemMarginRefundSwitchStatusForm')->option([
'_alias' => '审核表单',
'_auth' => false,
'_form' => 'systemMarginRefundSwitchStatus',
]);
Route::post('refund/status/:id', 'financial.Financial/switchStatus')->name('systemMarginRefundSwitchStatus')->append(['type' => 1])->option([
'_alias' => '审核',
]);
//备注
Route::get('refund/mark/:id/form', 'financial.Financial/markMarginForm')->name('systemMarginRefundMarkForm')->option([
'_alias' => '备注表单',
'_auth' => false,
'_form' => 'systemMarginRefundMark',
]);
Route::post('refund/mark/:id', 'financial.Financial/mark')->name('systemMarginRefundMark')->option([
'_alias' => '备注',
]);
Route::get('make_up', 'supply.Supply/makeUpMarginLst')->name('systemMarginMakeUpMarginLst')->option([
'_alias' => '待缴列表',
]);
//线下缴纳
Route::get('local/:id/form', 'supply.SupplyMargin/localMarginForm')->name('systemMarginLocalForm')->option([
'_alias' => '扣除保证金表单',
'_auth' => false,
'_form' => 'systemMarginSet',
]);
Route::post('local/:id', 'supply.SupplyMargin/localMarginSet')->name('systemMarginLocalSet')->option([
'_alias' => '扣除保证金表单',
'_auth' => false,
'_form' => 'systemMarginLocalSet',
]);
})->prefix('admin.system.')->option([
'_path' => '/supply/deposit_list',
'_auth' => true,
]);
})->middleware(AllowOriginMiddleware::class)
->middleware(AdminTokenMiddleware::class, true)
->middleware(AdminAuthMiddleware::class)
->middleware(LogMiddleware::class);