| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Api;
- use App\Models\AccountLogModel;
- use App\Models\MeetingModel;
- use App\Models\StoreModel;
- use App\Services\BaseService;
- use App\Services\RedisService;
- use Illuminate\Support\Facades\DB;
- /**
- * 结算管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * @package App\Services\Api
- */
- class SettleService extends BaseService
- {
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- */
- public function __construct()
- {
- $this->model = new AccountLogModel();
- }
- /**
- * 静态入口
- * @return static|null
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = (new static());
- }
- return self::$instance;
- }
- /**
- * 商家收益结算
- * @param $storeId
- * @param $money 收益
- * @param $order 订单数据
- * @return array|false|int
- */
- public function storeBonus($storeId, $money, $order)
- {
- $orderNo = isset($order['order_no'])? $order['order_no'] : '';
- if($money<=0 && $storeId<=0){
- $this->error = '无企业佣金可结算';
- return false;
- }
- $storeInfo = StoreModel::where(['id'=> $storeId,'mark'=>1])->first();
- $balance = isset($storeInfo['bonus_total'])? $storeInfo['bonus_total'] : 0;
- $storeUserId = isset($storeInfo['user_id'])? $storeInfo['user_id'] : 0;
- if($storeUserId<=0){
- $this->error = '企业账号错误';
- return false;
- }
- if(!StoreModel::where(['id'=> $storeId])->update(['bonus_total'=>DB::raw("bonus_total + {$money}"),'update_time'=>time()])){
- $this->error = '收货错误,企业结算错误,请联系客服处理';
- return -1;
- }
- $log = [
- 'user_id'=> $storeUserId,
- 'store_id'=> $storeId,
- 'source_order_no'=> isset($order['order_no'])? $order['order_no'] : '',
- 'type'=> 7,
- 'money'=> $money,
- 'after_money'=> moneyFormat($balance+$money,2),
- 'date'=>date('Y-m-d'),
- 'create_time'=>time(),
- 'remark'=> '收益',
- 'status'=>1
- ];
- if(!$id = $this->model->insertGetId($log)){
- $this->error = '企业收益结算失败,请联系客服处理';
- return -1;
- }
- $result = ['id'=>$id,'store_id'=>$storeId,'bonus'=>$money];
- if(env('APP_DEBUG')){
- RedisService::set("caches:settle:{$orderNo}:store_{$storeId}", $result, 7200);
- }
- return $result;
- }
- }
|