From d06160776f27943d4c821002d6a7ab5136de6a03 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 22 May 2024 16:05:49 +0800 Subject: [PATCH] =?UTF-8?q?5.22=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/merchat/MerchantController.php | 40 ++++++++++ .../supplier/SupplierController.php | 13 ++++ app/admin/logic/merchant/MerchantLogic.php | 54 ++++++++++++- .../logic/operation/OpurchaseclassLogic.php | 50 ++++++------ app/admin/logic/supplier/SupplierLogic.php | 53 +++++++++++++ app/api/controller/IndexController.php | 13 ++-- .../financial/FinancialRecordController.php | 44 +++++++++++ .../merchant/MerchantController.php | 68 +++++++++++++++- .../lists/financial/FinancialRecordLists.php | 77 ++++++++++++++++++ app/api/lists/merchant/MerchantLists.php | 3 +- app/api/logic/merchant/MerchantLogic.php | 78 +++++++++++++++++++ app/common/enum/OrderEnum.php | 4 + .../model/financial/FinancialRecord.php | 2 +- app/common/model/merchant/Merchant.php | 6 +- app/functions.php | 15 ++++ 15 files changed, 484 insertions(+), 36 deletions(-) create mode 100644 app/api/controller/financial/FinancialRecordController.php create mode 100644 app/api/lists/financial/FinancialRecordLists.php create mode 100644 app/api/logic/merchant/MerchantLogic.php diff --git a/app/admin/controller/merchat/MerchantController.php b/app/admin/controller/merchat/MerchantController.php index 2be89ab..f036d75 100644 --- a/app/admin/controller/merchat/MerchantController.php +++ b/app/admin/controller/merchat/MerchantController.php @@ -117,6 +117,20 @@ class MerchantController extends BaseAdminController return $this->success('删除成功', [], 1, 1); } + /** + * @notes 设置余额 + */ + public function set_money() + { + $set_money = $this->request->post('set_money', 0); + $id = $this->request->post('mer_id', 0); + $type = $this->request->post('type', 1); + $result = MerchantLogic::set_money($id, $set_money, $type); + if (true === $result) { + return $this->success('设置成功', [], 1, 1); + } + return $this->fail(MerchantLogic::getError()); + } /** * @notes 获取商户列表详情 @@ -131,6 +145,29 @@ class MerchantController extends BaseAdminController return $this->data($result); } + /** + * @notes 绑定用户 + */ + public function bind_user() + { + $params = $this->request->post(); + if (!isset($params['mer_id']) && !isset($params['uid'])) { + return $this->fail('参数错误'); + } + $find = Merchant::where('uid', $params['uid'])->find(); + if ($find) { + return $this->fail('该用户已绑定商户'); + } + $res = Merchant::where('mer_id', $params['mer_id'])->update(['uid' => $params['uid']]); + if ($res) { + return $this->success('绑定成功', [], 1, 1); + } + return $this->fail('绑定失败'); + } + + /** + * @notes 绑定商品 + */ public function bind_goods() { $params = (new MerchantValidate())->post()->goCheck('detail'); @@ -141,6 +178,9 @@ class MerchantController extends BaseAdminController return $this->fail(MerchantLogic::getError()); } + /** + * @notes 商品列表 + */ public function bind_goods_lists() { $mer_id = $this->request->get('mer_id'); diff --git a/app/admin/controller/supplier/SupplierController.php b/app/admin/controller/supplier/SupplierController.php index e9019f6..a060d49 100644 --- a/app/admin/controller/supplier/SupplierController.php +++ b/app/admin/controller/supplier/SupplierController.php @@ -96,6 +96,19 @@ class SupplierController extends BaseAdminController return $this->fail(SupplierLogic::getError()); } + /** + * @notes 设置余额 + */ + public function set_money(){ + $set_money = $this->request->post('set_money',0); + $id=$this->request->post('id',0); + $type=$this->request->post('type',1); + $result = SupplierLogic::set_money($id,$set_money,$type); + if (true === $result) { + return $this->success('设置成功', [], 1, 1); + } + return $this->fail(SupplierLogic::getError()); + } /** * @notes 删除供应商管理 * @return \think\response\Json diff --git a/app/admin/logic/merchant/MerchantLogic.php b/app/admin/logic/merchant/MerchantLogic.php index 7ca25d5..3282885 100644 --- a/app/admin/logic/merchant/MerchantLogic.php +++ b/app/admin/logic/merchant/MerchantLogic.php @@ -4,8 +4,10 @@ namespace app\admin\logic\merchant; use app\admin\logic\user\UserLogic; use app\admin\service\JgPushService; +use app\common\enum\OrderEnum; use app\common\model\merchant\Merchant; use app\common\logic\BaseLogic; +use app\common\model\financial\FinancialRecord; use app\common\model\user\User; use think\facade\Db; use support\exception\BusinessException; @@ -190,7 +192,57 @@ class MerchantLogic extends BaseLogic return false; } } - + /** + * @notes 设置余额 + */ + public static function set_money($id,$set_money,$type=1){ + Db::startTrans(); + try { + if($type==1){ + Merchant::where('mer_id',$id)->inc('mer_money',$set_money)->update(); + $record = [ + 'financial_record_sn' => time(), + 'order_id' => 0, + 'number_sn' =>getNewOrderId('XTCZ') , + 'user_id' => 0, + 'financial_type' => OrderEnum::SYSTEM_SET, + 'financial_pm' => OrderEnum::INCOME, + 'number' => $set_money, + 'status' => 1, + 'type' => OrderEnum::MERCHANT, + 'mer_id' => $id, + ]; + FinancialRecord::create($record); + }else{ + $money=Merchant::where('mer_id',$id)->value('mer_money'); + if($money<$set_money){ + Db::rollback(); + self::setError('余额不足'); + return false; + } + Merchant::where('mer_id',$id)->dec('mer_money',$set_money)->update(); + $record = [ + 'financial_record_sn' => time(), + 'order_id' => 0, + 'number_sn' =>getNewOrderId('XTJS') , + 'user_id' => 0, + 'financial_type' => OrderEnum::SYSTEM_SET, + 'financial_pm' => OrderEnum::EXPENDITURE, + 'number' => $set_money, + 'status' => 1, + 'type' => OrderEnum::MERCHANT, + 'mer_id' => $id, + ]; + FinancialRecord::create($record); + } + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } /** * @notes 商户绑定商品 * @param array $params diff --git a/app/admin/logic/operation/OpurchaseclassLogic.php b/app/admin/logic/operation/OpurchaseclassLogic.php index c95ec39..b3e8992 100644 --- a/app/admin/logic/operation/OpurchaseclassLogic.php +++ b/app/admin/logic/operation/OpurchaseclassLogic.php @@ -196,30 +196,36 @@ class OpurchaseclassLogic extends BaseLogic public static function createSupplierGoods($goods) { try { - $supplier_arr=SupplierBindGoods::where('goods_id')->column('supplier_id'); - if($supplier_arr){ - $supplier_arr=array_unique($supplier_arr); - foreach ($supplier_arr as $k => $v) { - $goods_offer[] = [ - 'supplier_id' => $v['id'], - 'goods_id' => $goods['goods'], - 'order_id' => $goods['pid'], - 'price' => 0, - 'need_num' => $goods['nums'], - 'create_time'=>time() - ]; - } - if (count($goods_offer) >= 1) { - $res = OpurchaseGoodsOffer::insertAll($goods_offer); - if ($res) { - Opurchaseinfo::where('id',$goods['id'])->update(['is_push'=>1]); - return $goods_offer; + $supplier_arr = SupplierBindGoods::where('goods_id')->column('supplier_id'); + if ($supplier_arr) { + $supplier_arr = array_unique($supplier_arr); + $time=strtotime(date('Y-m-d',time())); + foreach ($supplier_arr as $k => $v) { + $goods_offer[] = [ + 'supplier_id' => $v['id'], + 'goods_id' => $goods['goods'], + 'order_id' => $goods['pid'], + 'price' => 0, + 'need_num' => $goods['nums'], + 'create_time' => time() + ]; + $find=Db::name('opurchase_goods_offer_date')->where('supplier_id',$v)->where('create_time',$time)->find(); + if($find){ + Db::name('opurchase_goods_offer_date')->where('id',$find['id'])->inc('nums')->update(); + }else{ + $data=['supplier_id'=>$v,'nums'=>1,'create_time'=>$time]; + Db::name('opurchase_goods_offer_date')->insert($data); + } } + if (count($goods_offer) >= 1) { + $res = OpurchaseGoodsOffer::insertAll($goods_offer); + if ($res) { + Opurchaseinfo::where('id', $goods['id'])->update(['is_push' => 1]); + return $goods_offer; + } + } + } else { } - }else{ - - } - } catch (\Exception $e) { self::setError($e->getMessage()); Log::error('添加采购订单报价失败:' . $e->getMessage()); diff --git a/app/admin/logic/supplier/SupplierLogic.php b/app/admin/logic/supplier/SupplierLogic.php index 10112bd..7f22435 100644 --- a/app/admin/logic/supplier/SupplierLogic.php +++ b/app/admin/logic/supplier/SupplierLogic.php @@ -4,10 +4,12 @@ namespace app\admin\logic\supplier; use app\admin\logic\user\UserLogic; use app\admin\service\JgPushService; +use app\common\enum\OrderEnum; use app\common\model\goods\GoodsLabel; use app\common\model\merchant\MerchantBank; use app\common\model\supplier\Supplier; use app\common\logic\BaseLogic; +use app\common\model\financial\FinancialRecord; use think\facade\Db; use support\exception\BusinessException; @@ -199,6 +201,57 @@ class SupplierLogic extends BaseLogic } } + /** + * @notes 设置余额 + */ + public static function set_money($id,$set_money,$type=1){ + Db::startTrans(); + try { + if($type==1){ + Supplier::where('id',$id)->inc('mer_money',$set_money)->update(); + $record = [ + 'financial_record_sn' => time(), + 'order_id' => 0, + 'number_sn' =>getNewOrderId('XTCZ') , + 'user_id' => 0, + 'financial_type' => OrderEnum::SYSTEM_SET, + 'financial_pm' => OrderEnum::INCOME, + 'number' => $set_money, + 'status' => 1, + 'type' => OrderEnum::SUPPLIER, + 'mer_id' => $id, + ]; + FinancialRecord::create($record); + }else{ + $money=Supplier::where('id',$id)->value('mer_money'); + if($money<$set_money){ + Db::rollback(); + self::setError('余额不足'); + return false; + } + Supplier::where('id',$id)->dec('mer_money',$set_money)->update(); + $record = [ + 'financial_record_sn' => time(), + 'order_id' => 0, + 'number_sn' =>getNewOrderId('XTJS') , + 'user_id' => 0, + 'financial_type' => OrderEnum::SYSTEM_SET, + 'financial_pm' => OrderEnum::EXPENDITURE, + 'number' => $set_money, + 'status' => 1, + 'type' => OrderEnum::SUPPLIER, + 'mer_id' => $id, + ]; + FinancialRecord::create($record); + } + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } /** * @notes 删除供应商管理 diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 4419de8..e6ad97e 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -26,16 +26,15 @@ class IndexController extends BaseApiController public function index() { - $client = new JPush($app_key, $master_secret); + // $client = new JPush($app_key, $master_secret); - $client->push() - ->setPlatform('all') - ->addAllAudience() - ->setNotificationAlert('Hello, JPush') - ->send(); + // $client->push() + // ->setPlatform('all') + // ->addAllAudience() + // ->setNotificationAlert('Hello, JPush') + // ->send(); -d($token); // var_dump(2323); return json(['msg' =>create_password(123456, '11d3')]); // PushService::push('store_merchant_502', 502, '支付超时,订单已被取消,请重新提交订单'); diff --git a/app/api/controller/financial/FinancialRecordController.php b/app/api/controller/financial/FinancialRecordController.php new file mode 100644 index 0000000..45533b1 --- /dev/null +++ b/app/api/controller/financial/FinancialRecordController.php @@ -0,0 +1,44 @@ +request->get('start_time'); + $end_time = $this->request->get('end_time'); + if(!isset($start_time)||!isset($end_time)){ + return $this->fail('请选择时间'); + } + $start_time = strtotime($start_time); // 开始时间 + $end_time = strtotime($end_time); // 结束时间 + + // 计算时间差 + $time_diff = $end_time - $start_time; + + // 7天内的秒数 + $seven_days_in_seconds = 7 * 24 * 60 * 60; + + // 验证时间差是否在7天内 + if ($time_diff > $seven_days_in_seconds) { + return $this->fail('时间差不能超过7天'); + } + return $this->dataLists((new FinancialRecordLists)); + } +} diff --git a/app/api/controller/merchant/MerchantController.php b/app/api/controller/merchant/MerchantController.php index ff532bd..0ac5144 100644 --- a/app/api/controller/merchant/MerchantController.php +++ b/app/api/controller/merchant/MerchantController.php @@ -2,14 +2,76 @@ namespace app\api\controller\merchant; +use app\admin\validate\withdraw\MerchantWithdrawValidate; use app\api\lists\merchant\MerchantLists; use app\api\controller\BaseApiController; - +use app\api\lists\withdraw\MerchantWithdrawLists; +use app\api\logic\merchant\MerchantLogic; class MerchantController extends BaseApiController { - public function lists(){ + public function lists() + { return $this->dataLists(new MerchantLists()); } -} \ No newline at end of file + //提现列表 + public function taking_lists() + { + return $this->dataLists(new MerchantWithdrawLists()); + } + //获取用户余额和绑定银行账户信息 + public function amount_account() + { + $merchant = $this->request->userInfo['merchant']; + if (!$merchant) { + return $this->fail('当前用户非商户'); + } + if (!$merchant->isEmpty()) { + $res=MerchantLogic::amount_account($merchant); + if(MerchantLogic::hasError()){ + return $this->fail(MerchantLogic::getError()); + } + return $this->success('获取成功',$res); + } + return $this->fail('获取失败'); + } + + //用户提现操作 + public function withdraw() + { + $params = (new MerchantWithdrawValidate())->post()->goCheck('withdraw'); + $merchant = $this->request->userInfo['merchant']; + if (!$merchant) { + return $this->fail('当前用户非商户'); + } + if (!$merchant->isEmpty()) { + MerchantLogic::withdraw($params,$merchant); + if(MerchantLogic::hasError()){ + return $this->fail(MerchantLogic::getError()); + } + return $this->success('提现成功,等待管理员审核'); + } + return $this->fail('提现异常'); + } + + /** + * 提现信息 + */ + public function taking_info() + { + $merchant = $this->request->userInfo['merchant']; + if (!$merchant) { + return $this->fail('当前用户非商户'); + } + + if (!$merchant->isEmpty()) { + $res=MerchantLogic::taking_info($merchant); + if(MerchantLogic::hasError()){ + return $this->fail(MerchantLogic::getError()); + } + return $this->success('ok',$res); + } + return $this->success('ok'); + } +} diff --git a/app/api/lists/financial/FinancialRecordLists.php b/app/api/lists/financial/FinancialRecordLists.php new file mode 100644 index 0000000..0009456 --- /dev/null +++ b/app/api/lists/financial/FinancialRecordLists.php @@ -0,0 +1,77 @@ + ['financial_pm'], + "between_time" => 'create_time' + ]; + } + + + /** + * @notes 获取商户财务记列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/04/23 10:27 + */ + public function lists(): array + { + $mer_id = $this->request->userInfo['merchant']['mer_id'] ?? 0; + if ($mer_id <= 0) { + return []; + } + $where = [ + 'type' => 1, + 'mer_id' => $mer_id, + ]; + $this->where = $where; + $list = FinancialRecord::where($this->searchWhere) + ->where($where) + ->field("FROM_UNIXTIME(create_time, '%Y-%m-%d') as record_date, SUM(number) as total_amount") + ->group('record_date') + ->order('record_date') + ->select(); + return $list?->toArray(); + } + + + /** + * @notes 获取商户财务记数量 + * @return int + * @author likeadmin + * @date 2024/04/23 10:27 + */ + public function count(): int + { + + return FinancialRecord::where($this->searchWhere) + ->where($this->where) + ->count(); + } +} diff --git a/app/api/lists/merchant/MerchantLists.php b/app/api/lists/merchant/MerchantLists.php index 897bcd6..05c35b1 100644 --- a/app/api/lists/merchant/MerchantLists.php +++ b/app/api/lists/merchant/MerchantLists.php @@ -53,7 +53,8 @@ class MerchantLists extends BaseAdminDataLists implements ListsSearchInterface ) ASC "); } return Merchant::where($this->searchWhere) - ->field('mer_id,mer_name,long,lat,service_phone,mer_address') + ->with(['realName']) + ->field('mer_id,mer_name,long,lat,service_phone,mer_address,uid') ->limit($this->limitOffset, $this->limitLength) ->order($order) ->select() diff --git a/app/api/logic/merchant/MerchantLogic.php b/app/api/logic/merchant/MerchantLogic.php new file mode 100644 index 0000000..cba738b --- /dev/null +++ b/app/api/logic/merchant/MerchantLogic.php @@ -0,0 +1,78 @@ +where('is_check', 1)->select()->each(function ($data) { + $bank_info = Bank::where('id', $data['bank_id'])->findOrEmpty(); + $data['bank_name'] = !$bank_info->isEmpty() ? $bank_info['name'] : ''; + $data['bank_image'] = !$bank_info->isEmpty() ? $bank_info['image'] : ''; + return $data; + })->toArray(); + return $bank_list; + } catch (\Exception $e) { + self::setError($e->getMessage()); + return false; + } + } + + /** + * 用户提现操作 + */ + public static function withdraw($params, $merchant) + { + try { + $merchant = Merchant::where('mer_id', $merchant['mer_id'])->find(); + if ($params['amount'] > $merchant['mer_money']) { + self::setError('提现余额不足'); + return false; + } + $save_data = [ + 'mer_id' => $merchant['mer_id'], + 'merchant_bank_id' => $params['merchant_bank_id'], + 'amount' => $params['amount'], + 'is_check' => 0, + 'is_arrival' => 0, + 'admin_id' => 0, + 'create_time' => time(), + ]; + (new MerchantWithdraw)->save($save_data); + return true; + } catch (\Exception $e) { + self::setError($e->getMessage()); + return false; + } + } + + /** + * 提现信息 + */ + public static function taking_info($merchant){ + try { + $total_amount = MerchantWithdraw::where('mer_id', $merchant['mer_id'])->where('is_check', 1)->where('is_arrival', 1)->sum('amount'); + $count = MerchantWithdraw::where('mer_id', $merchant['mer_id'])->where('is_check', 1)->where('is_arrival', 1)->count(); + return ['total' => $total_amount, 'count' => $count]; + } catch (\Exception $e) { + self::setError($e->getMessage()); + return false; + } + + } +} diff --git a/app/common/enum/OrderEnum.php b/app/common/enum/OrderEnum.php index f33507d..3673592 100644 --- a/app/common/enum/OrderEnum.php +++ b/app/common/enum/OrderEnum.php @@ -15,6 +15,7 @@ class OrderEnum * @PLATFORM_ORDER_OBTAINS 平台订单获得 * @SUPPLIER_ORDER_OBTAINS 供应链订单获得 * @PLATFORM_ORDER_PAY 平台订单支付 + * @SYSTEM_SET 系统设置 */ const USER_ORDER_PAY = 1; const MERCHANT_ORDER_OBTAINS = 2; @@ -23,6 +24,7 @@ class OrderEnum const PLATFORM_ORDER_OBTAINS = 5; const SUPPLIER_ORDER_OBTAINS = 6; const PLATFORM_ORDER_PAY = 7; + const SYSTEM_SET = 8; /** @@ -39,11 +41,13 @@ class OrderEnum * @MERCHANT 商户 * @PLATFORM 平台 * @SUPPLIER 供应链 + * @SYSTEM 系统 */ const USER =0; const MERCHANT =1; const PLATFORM =2; const SUPPLIER =3; + const SYSTEM=4; /** * @notes 获取支付类型 diff --git a/app/common/model/financial/FinancialRecord.php b/app/common/model/financial/FinancialRecord.php index ff4037e..3b68dad 100644 --- a/app/common/model/financial/FinancialRecord.php +++ b/app/common/model/financial/FinancialRecord.php @@ -8,7 +8,7 @@ use think\model\concern\SoftDelete; /** - * 采购订单模型 + * 财务流水模型 * Class FinancialRecord * @package app\common\model\FinancialRecord */ diff --git a/app/common/model/merchant/Merchant.php b/app/common/model/merchant/Merchant.php index 34af109..8e5314a 100644 --- a/app/common/model/merchant/Merchant.php +++ b/app/common/model/merchant/Merchant.php @@ -4,6 +4,7 @@ namespace app\common\model\merchant; use app\common\model\BaseModel; +use app\common\model\user\User; use think\model\concern\SoftDelete; @@ -19,5 +20,8 @@ class Merchant extends BaseModel protected $name = 'merchant'; protected $deleteTime = 'delete_time'; - + public function realName() + { + return $this->hasOne(User::class,'id','uid')->bind(['mer_real_name'=>'real_name']); + } } \ No newline at end of file diff --git a/app/functions.php b/app/functions.php index 4394147..3eaae0f 100644 --- a/app/functions.php +++ b/app/functions.php @@ -313,3 +313,18 @@ if (!function_exists('base64UrlDecode')) { return base64_decode($base64Padded); } } +if (!function_exists('getNewOrderId')) { + + /** + * @notes 获取订单号 + * @param $type + * @return string + */ + function getNewOrderId($type) + { + list($msec, $sec) = explode(' ', microtime()); + $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', ''); + $orderId = $type . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369)); + return $orderId; + } +}