Exppoints.php 5.9 KB

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