BonusHistory.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\common\model\user;
  13. use app\common\model\BaseModel;
  14. use app\common\service\Message;
  15. /**
  16. * 用户余额变动明细模型
  17. * Class BalanceLog
  18. * @package app\common\model\user
  19. */
  20. class BonusHistory extends BaseModel
  21. {
  22. // 定义表名
  23. protected $name = 'bonus_history';
  24. // 定义主键
  25. protected $pk = 'id';
  26. /**
  27. * 新增记录
  28. * @param $userId
  29. * @param $year
  30. * @param $month
  31. * @param $salesVolume
  32. * @param $refundVolume
  33. * @param $refundCount
  34. * @param $countOvertimeSign
  35. * @param $sumOvertimeSign
  36. * @param $bonusRate
  37. * @param $bonusMoney
  38. * @param bool $monthly
  39. * @return bool
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\DbException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. */
  44. public static function add($userId, $year,$month,$salesVolume,$refundVolume,$refundCount,$countOvertimeSign,$sumOvertimeSign,$bonusRate,$bonusMoney,$monthly =false)
  45. {
  46. $old = self::where(['user_id'=>$userId,'year'=>$year,'month'=>$month])->find();
  47. try {
  48. if ($old){
  49. if ($old->clearing_status == 1){
  50. log_record('已结userId::'.$userId.'-'.$year.$month);
  51. return false;
  52. }
  53. $data = ['sales_volume' => $salesVolume,
  54. 'refund_volume' => $refundVolume,
  55. 'refund_count' => $refundCount,
  56. 'overtime_receipt_count' => $countOvertimeSign,
  57. 'overtime_receipt_sum' => $sumOvertimeSign,
  58. 'bonus_rate' => $bonusRate,
  59. 'bonus_money' => $bonusMoney];
  60. if ($monthly == true){
  61. /* if ($old->clearing_status == 1){
  62. log_record('已结userId::'.$userId.'-'.$year.$month);
  63. return false;
  64. }*/
  65. $data['clearing_status'] = 1;
  66. }
  67. self::update($data,['id'=>$old->id]);
  68. }else{
  69. /* if ($bonusMoney == 0){
  70. return true;
  71. }*/
  72. $new = [
  73. 'user_id' => $userId,
  74. 'year' => $year,
  75. 'month' => $month,
  76. 'year_month' => $year.$month,
  77. 'sales_volume' => $salesVolume,
  78. 'refund_count' => $refundCount,
  79. 'overtime_receipt_count' => $countOvertimeSign,
  80. 'overtime_receipt_sum' => $sumOvertimeSign,
  81. 'bonus_rate' => $bonusRate,
  82. 'bonus_money' => $bonusMoney,
  83. 'create_time' => time()
  84. ];
  85. if ($monthly == true){
  86. $new['clearing_status'] = 1;
  87. }
  88. BonusHistory::create($new);
  89. //['user_id','year','month','sales_volume','refund_count','overtime_receipt_count','bonus_rate','bonus_money','create_time']
  90. }
  91. }catch (\Exception $e){
  92. $error = __METHOD__.',userid::'.$userId.",".$e->getMessage();
  93. log_record($error,'error');
  94. Message::wxRobot($error);
  95. return false;
  96. }
  97. return true;
  98. }
  99. /**
  100. * v1.3.6版本区分门店角色
  101. * @param $userId
  102. * @param $year
  103. * @param $month
  104. * @param $shopId
  105. * @param $role
  106. * @param $salesVolume
  107. * @param $refundVolume
  108. * @param $refundCount
  109. * @param $countOvertimeSign
  110. * @param $sumOvertimeSign
  111. * @param $bonusRate
  112. * @param $bonusMoney
  113. * @param $orderCount
  114. * @param $bonusLadder
  115. * @param false $monthly
  116. * @return bool
  117. * @throws \think\db\exception\DataNotFoundException
  118. * @throws \think\db\exception\DbException
  119. * @throws \think\db\exception\ModelNotFoundException
  120. */
  121. public static function add36($userId, $year,$month,$shopId,$role,$salesVolume,$refundVolume,$refundCount,$countOvertimeSign,$sumOvertimeSign,$bonusRate,$bonusMoney,$orderCount,$bonusLadder,$monthly =false)
  122. {
  123. $old = self::where(['user_id'=>$userId,'year'=>$year,'month'=>$month,'shop_id'=>$shopId,'role'=>$role])->find();
  124. try {
  125. if ($old){
  126. if ($old->clearing_status == 1){
  127. log_record('已结userId::'.$userId.'-'.$year.$month);
  128. return false;
  129. }
  130. $data = [
  131. 'sales_volume' => $salesVolume,
  132. 'refund_volume' => $refundVolume,
  133. 'refund_count' => $refundCount,
  134. 'overtime_receipt_count' => $countOvertimeSign,
  135. 'overtime_receipt_sum' => $sumOvertimeSign,
  136. 'bonus_rate' => $bonusRate,
  137. 'bonus_money' => $bonusMoney,
  138. 'order_count' => $orderCount,
  139. 'bonus_ladder' => $bonusLadder,
  140. ];
  141. if ($monthly == true){
  142. $data['clearing_status'] = 1;
  143. }
  144. self::update($data,['id'=>$old->id]);
  145. }else{
  146. $new = [
  147. 'user_id' => $userId,
  148. 'year' => $year,
  149. 'month' => $month,
  150. 'year_month' => $year.($month < 10?('0'.$month):$month),
  151. 'shop_id' =>$shopId,
  152. 'role' =>$role,
  153. 'sales_volume' => $salesVolume,
  154. 'refund_volume' => $refundVolume,
  155. 'refund_count' => $refundCount,
  156. 'overtime_receipt_count' => $countOvertimeSign,
  157. 'overtime_receipt_sum' => $sumOvertimeSign,
  158. 'bonus_rate' => $bonusRate,
  159. 'bonus_money' => $bonusMoney,
  160. 'order_count' => $orderCount,
  161. 'bonus_ladder' => $bonusLadder,
  162. 'create_time' => time()
  163. ];
  164. if ($monthly == true){
  165. $new['clearing_status'] = 1;
  166. }
  167. BonusHistory::create($new);
  168. //['user_id','year','month','sales_volume','refund_count','overtime_receipt_count','bonus_rate','bonus_money','create_time']
  169. }
  170. }catch (\Exception $e){
  171. $error = __METHOD__.',userid::'.$userId.",".$e->getMessage();
  172. log_record($error,'error');
  173. Message::wxRobot($error);
  174. return false;
  175. }
  176. return true;
  177. }
  178. }