Point.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\model\account;
  11. use app\model\BaseModel;
  12. use app\model\member\MemberAccount;
  13. use app\model\message\Message;
  14. use app\model\message\Sms;
  15. use addon\wechat\model\Message as WechatMessage;
  16. use app\model\member\Member as MemberModel;
  17. use addon\weapp\model\Message as WeappMessage;
  18. use think\facade\Db;
  19. /**
  20. * 积分管理
  21. */
  22. class Point extends BaseModel
  23. {
  24. /**
  25. * 积分清零
  26. * @param $params
  27. * @return array
  28. */
  29. public function pointClear($params)
  30. {
  31. $site_id = $params[ 'site_id' ] ?? 0;
  32. try {
  33. set_time_limit(0);
  34. $condition = array (
  35. [ 'point', '>', 0 ]
  36. );
  37. if ($site_id > 0) {
  38. $condition[] = [ 'site_id', '=', $site_id ];
  39. }
  40. $list = model('member')->getList($condition, 'member_id,site_id, point');
  41. if (empty($list)) {
  42. return $this->success();
  43. }
  44. $member_account_model = new MemberAccount();
  45. $remark = empty($params[ 'remark' ]) ? '积分清零' : $params[ 'remark' ];
  46. foreach ($list as $k => $val) {
  47. $member_account_model->addMemberAccount($val[ 'site_id' ], $val[ 'member_id' ], "point", -$val[ 'point' ], 'point_set_zero', 0, $remark);
  48. }
  49. return $this->success();
  50. } catch (\Exception $e) {
  51. return $this->error('', $e->getMessage());
  52. }
  53. }
  54. /**
  55. * 积分重置
  56. * @param $params
  57. */
  58. public function pointReset($params)
  59. {
  60. $site_id = $params[ 'site_id' ];
  61. //会员积分清零
  62. $condition = array (
  63. [ 'point', '<>', 0 ]
  64. );
  65. $common_condition = [];
  66. if ($site_id > 0) {
  67. $common_condition[] = [ 'site_id', '=', $site_id ];
  68. }
  69. $member_data = array (
  70. 'point' => 0
  71. );
  72. model('member')->update($member_data, array_merge($condition, $common_condition));
  73. //会员积分记录清空删除
  74. $member_account_condition = array (
  75. [ 'account_type', '=', 'point' ]
  76. );
  77. model('member_account')->delete(array_merge($member_account_condition, $common_condition));
  78. return $this->success();
  79. }
  80. }