Exppoints.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 数据层模型
  14. */
  15. class Exppoints extends BaseModel {
  16. public $page_info;
  17. /**
  18. * 操作经验值
  19. * @access public
  20. * @author csdeshang
  21. * @param string $stage 操作阶段 login(登录),comments(评论),order(下单)
  22. * @param array $insertarr 该数组可能包含信息 array('explog_memberid'=>'会员编号','explog_membername'=>'会员名称','explog_points'=>'经验值','explog_desc'=>'描述','orderprice'=>'订单金额','order_sn'=>'订单编号','order_id'=>'订单序号');
  23. * @return bool
  24. */
  25. function saveExppointslog($stage, $insertarr) {
  26. if (!$insertarr['explog_memberid']) {
  27. return false;
  28. }
  29. $exppoints_rule = config("ds_config.exppoints_rule") ? unserialize(config("ds_config.exppoints_rule")) : array();
  30. if(empty($exppoints_rule['exp_login'])){
  31. return;
  32. }
  33. //记录原因文字
  34. switch ($stage) {
  35. case 'login':
  36. if (!isset($insertarr['explog_desc'])) {
  37. $insertarr['explog_desc'] = '会员登录';
  38. }
  39. $insertarr['explog_points'] = 0;
  40. if (intval($exppoints_rule['exp_login']) > 0) {
  41. $insertarr['explog_points'] = intval($exppoints_rule['exp_login']);
  42. }
  43. break;
  44. case 'comments':
  45. if (!isset($insertarr['explog_desc'])) {
  46. $insertarr['explog_desc'] = '评论商品';
  47. }
  48. $insertarr['explog_points'] = 0;
  49. if (intval($exppoints_rule['exp_comments']) > 0) {
  50. $insertarr['explog_points'] = intval($exppoints_rule['exp_comments']);
  51. }
  52. break;
  53. case 'system':
  54. break;
  55. case 'order':
  56. if (!isset($insertarr['explog_desc'])) {
  57. $insertarr['explog_desc'] = '订单' . $insertarr['order_sn'] . '购物消费';
  58. }
  59. $insertarr['explog_points'] = 0;
  60. $exppoints_rule['exp_orderrate'] = floatval($exppoints_rule['exp_orderrate']);
  61. if ($insertarr['orderprice'] && $exppoints_rule['exp_orderrate'] > 0) {
  62. $insertarr['explog_points'] = @intval($insertarr['orderprice'] / $exppoints_rule['exp_orderrate']);
  63. $exp_ordermax = intval($exppoints_rule['exp_ordermax']);
  64. if ($exp_ordermax > 0 && $insertarr['explog_points'] > $exp_ordermax) {
  65. $insertarr['explog_points'] = $exp_ordermax;
  66. }
  67. }
  68. break;
  69. }
  70. //新增日志
  71. $value_array = array();
  72. $value_array['explog_memberid'] = $insertarr['explog_memberid'];
  73. $value_array['explog_membername'] = $insertarr['explog_membername'];
  74. $value_array['explog_points'] = $insertarr['explog_points'];
  75. $value_array['explog_addtime'] = TIMESTAMP;
  76. $value_array['explog_desc'] = $insertarr['explog_desc'];
  77. $value_array['explog_stage'] = $stage;
  78. $result = false;
  79. if ($value_array['explog_points'] != '0') {
  80. $result = self::addExppointslog($value_array);
  81. }
  82. if ($result) {
  83. //更新member内容
  84. $obj_member = model('member');
  85. $upmember_array = array();
  86. $upmember_array['member_exppoints'] = Db::raw('member_exppoints+'.$insertarr['explog_points']);
  87. $obj_member->editMember(array('member_id' => $insertarr['explog_memberid']), $upmember_array,$insertarr['explog_memberid']);
  88. return true;
  89. } else {
  90. return false;
  91. }
  92. }
  93. /**
  94. * 添加经验值日志信息
  95. * @access public
  96. * @author csdeshang
  97. * @param array $data 添加信息数组
  98. * @return array
  99. */
  100. public function addExppointslog($data) {
  101. if (empty($data)) {
  102. return false;
  103. }
  104. $result = Db::name('exppointslog')->insertGetId($data);
  105. return $result;
  106. }
  107. /**
  108. * 经验值日志总条数
  109. * @access public
  110. * @author csdeshang
  111. * @param array $where 条件数组
  112. * @param string $field 查询字段
  113. * @return int
  114. */
  115. public function getExppointslogCount($where, $field = '*') {
  116. $count = Db::name('exppointslog')->field($field)->where($where)->count();
  117. return $count;
  118. }
  119. /**
  120. * 经验值日志列表
  121. * @access public
  122. * @author csdeshang
  123. * @param array $where 条件数组
  124. * @param string $field 查询字段
  125. * @param int $pagesize 分页信息
  126. * @param string $order 排序
  127. * @return array
  128. */
  129. public function getExppointslogList($where, $field = '*', $pagesize = 0, $order = '') {
  130. if($pagesize){
  131. $result = Db::name('exppointslog')->field($field)->where($where)->order($order)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  132. $this->page_info = $result;
  133. $res = $result->items();
  134. }else{
  135. $res = Db::name('exppointslog')->field($field)->where($where)->order($order)->select()->toArray();
  136. }
  137. return $res;
  138. }
  139. /**
  140. * 获得阶段说明文字
  141. * @access public
  142. * @author csdeshang
  143. * @return string
  144. */
  145. public function getExppointsStage() {
  146. $stage_arr = array();
  147. $stage_arr['login'] = '会员登录';
  148. $stage_arr['comments'] = '商品评论';
  149. $stage_arr['order'] = '订单消费';
  150. $stage_arr['system'] = '系统调整';
  151. return $stage_arr;
  152. }
  153. }
  154. ?>