Exppoints.php 6.1 KB

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