123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- <?php
- // +----------------------------------------------------------------------
- // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: 萤火科技 <admin@yiovo.com>
- // +----------------------------------------------------------------------
- declare (strict_types = 1);
- namespace app\common\model\user;
- use app\common\model\BaseModel;
- use app\common\service\Message;
- /**
- * 用户余额变动明细模型
- * Class BalanceLog
- * @package app\common\model\user
- */
- class BonusHistory extends BaseModel
- {
- // 定义表名
- protected $name = 'bonus_history';
- // 定义主键
- protected $pk = 'id';
- /**
- * 新增记录
- * @param $userId
- * @param $year
- * @param $month
- * @param $salesVolume
- * @param $refundVolume
- * @param $refundCount
- * @param $countOvertimeSign
- * @param $sumOvertimeSign
- * @param $bonusRate
- * @param $bonusMoney
- * @param bool $monthly
- * @return bool
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public static function add($userId, $year,$month,$salesVolume,$refundVolume,$refundCount,$countOvertimeSign,$sumOvertimeSign,$bonusRate,$bonusMoney,$monthly =false)
- {
- $old = self::where(['user_id'=>$userId,'year'=>$year,'month'=>$month])->find();
- try {
- if ($old){
- if ($old->clearing_status == 1){
- log_record('已结userId::'.$userId.'-'.$year.$month);
- return false;
- }
- $data = ['sales_volume' => $salesVolume,
- 'refund_volume' => $refundVolume,
- 'refund_count' => $refundCount,
- 'overtime_receipt_count' => $countOvertimeSign,
- 'overtime_receipt_sum' => $sumOvertimeSign,
- 'bonus_rate' => $bonusRate,
- 'bonus_money' => $bonusMoney];
- if ($monthly == true){
- /* if ($old->clearing_status == 1){
- log_record('已结userId::'.$userId.'-'.$year.$month);
- return false;
- }*/
- $data['clearing_status'] = 1;
- }
- self::update($data,['id'=>$old->id]);
- }else{
- /* if ($bonusMoney == 0){
- return true;
- }*/
- $new = [
- 'user_id' => $userId,
- 'year' => $year,
- 'month' => $month,
- 'year_month' => $year.$month,
- 'sales_volume' => $salesVolume,
- 'refund_count' => $refundCount,
- 'overtime_receipt_count' => $countOvertimeSign,
- 'overtime_receipt_sum' => $sumOvertimeSign,
- 'bonus_rate' => $bonusRate,
- 'bonus_money' => $bonusMoney,
- 'create_time' => time()
- ];
- if ($monthly == true){
- $new['clearing_status'] = 1;
- }
- BonusHistory::create($new);
- //['user_id','year','month','sales_volume','refund_count','overtime_receipt_count','bonus_rate','bonus_money','create_time']
- }
- }catch (\Exception $e){
- $error = __METHOD__.',userid::'.$userId.",".$e->getMessage();
- log_record($error,'error');
- Message::wxRobot($error);
- return false;
- }
- return true;
- }
- /**
- * v1.3.6版本区分门店角色
- * @param $userId
- * @param $year
- * @param $month
- * @param $shopId
- * @param $role
- * @param $salesVolume
- * @param $refundVolume
- * @param $refundCount
- * @param $countOvertimeSign
- * @param $sumOvertimeSign
- * @param $bonusRate
- * @param $bonusMoney
- * @param $orderCount
- * @param $bonusLadder
- * @param false $monthly
- * @return bool
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public static function add36($userId, $year,$month,$shopId,$role,$salesVolume,$refundVolume,$refundCount,$countOvertimeSign,$sumOvertimeSign,$bonusRate,$bonusMoney,$orderCount,$bonusLadder,$monthly =false)
- {
- $old = self::where(['user_id'=>$userId,'year'=>$year,'month'=>$month,'shop_id'=>$shopId,'role'=>$role])->find();
- try {
- if ($old){
- if ($old->clearing_status == 1){
- log_record('已结userId::'.$userId.'-'.$year.$month);
- return false;
- }
- $data = [
- 'sales_volume' => $salesVolume,
- 'refund_volume' => $refundVolume,
- 'refund_count' => $refundCount,
- 'overtime_receipt_count' => $countOvertimeSign,
- 'overtime_receipt_sum' => $sumOvertimeSign,
- 'bonus_rate' => $bonusRate,
- 'bonus_money' => $bonusMoney,
- 'order_count' => $orderCount,
- 'bonus_ladder' => $bonusLadder,
- ];
- if ($monthly == true){
- $data['clearing_status'] = 1;
- }
- self::update($data,['id'=>$old->id]);
- }else{
- $new = [
- 'user_id' => $userId,
- 'year' => $year,
- 'month' => $month,
- 'year_month' => $year.($month < 10?('0'.$month):$month),
- 'shop_id' =>$shopId,
- 'role' =>$role,
- 'sales_volume' => $salesVolume,
- 'refund_volume' => $refundVolume,
- 'refund_count' => $refundCount,
- 'overtime_receipt_count' => $countOvertimeSign,
- 'overtime_receipt_sum' => $sumOvertimeSign,
- 'bonus_rate' => $bonusRate,
- 'bonus_money' => $bonusMoney,
- 'order_count' => $orderCount,
- 'bonus_ladder' => $bonusLadder,
- 'create_time' => time()
- ];
- if ($monthly == true){
- $new['clearing_status'] = 1;
- }
- BonusHistory::create($new);
- //['user_id','year','month','sales_volume','refund_count','overtime_receipt_count','bonus_rate','bonus_money','create_time']
- }
- }catch (\Exception $e){
- $error = __METHOD__.',userid::'.$userId.",".$e->getMessage();
- log_record($error,'error');
- Message::wxRobot($error);
- return false;
- }
- return true;
- }
- }
|