Exppoints.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 数据层模型
  15. */
  16. class Exppoints extends BaseModel {
  17. public $page_info;
  18. /**
  19. * 操作经验值
  20. * @access public
  21. * @author csdeshang
  22. * @param string $stage 操作阶段 login(登录),comments(评论),order(下单)
  23. * @param array $insertarr 该数组可能包含信息 array('explog_memberid'=>'会员编号','explog_membername'=>'会员名称','explog_points'=>'经验值','explog_desc'=>'描述','orderprice'=>'订单金额','order_sn'=>'订单编号','order_id'=>'订单序号');
  24. * @return bool
  25. */
  26. function saveExppointslog($stage, $insertarr) {
  27. if (!$insertarr['explog_memberid']) {
  28. return false;
  29. }
  30. $exppoints_rule = config("ds_config.exppoints_rule") ? unserialize(config("ds_config.exppoints_rule")) : array();
  31. if(empty($exppoints_rule['exp_login'])){
  32. return;
  33. }
  34. //记录原因文字
  35. switch ($stage) {
  36. case 'login':
  37. if (!isset($insertarr['explog_desc'])) {
  38. $insertarr['explog_desc'] = '会员登录';
  39. }
  40. $insertarr['explog_points'] = 0;
  41. if (intval($exppoints_rule['exp_login']) > 0) {
  42. $insertarr['explog_points'] = intval($exppoints_rule['exp_login']);
  43. }
  44. break;
  45. case 'comments':
  46. if (!isset($insertarr['explog_desc'])) {
  47. $insertarr['explog_desc'] = '评论商品';
  48. }
  49. $insertarr['explog_points'] = 0;
  50. if (intval($exppoints_rule['exp_comments']) > 0) {
  51. $insertarr['explog_points'] = intval($exppoints_rule['exp_comments']);
  52. }
  53. break;
  54. case 'system':
  55. break;
  56. case 'order':
  57. if (!isset($insertarr['explog_desc'])) {
  58. $insertarr['explog_desc'] = '订单' . $insertarr['order_sn'] . '购物消费';
  59. }
  60. $insertarr['explog_points'] = 0;
  61. $exppoints_rule['exp_orderrate'] = floatval($exppoints_rule['exp_orderrate']);
  62. if ($insertarr['orderprice'] && $exppoints_rule['exp_orderrate'] > 0) {
  63. $insertarr['explog_points'] = @intval($insertarr['orderprice'] / $exppoints_rule['exp_orderrate']);
  64. $exp_ordermax = intval($exppoints_rule['exp_ordermax']);
  65. if ($exp_ordermax > 0 && $insertarr['explog_points'] > $exp_ordermax) {
  66. $insertarr['explog_points'] = $exp_ordermax;
  67. }
  68. }
  69. break;
  70. }
  71. //新增日志
  72. $value_array = array();
  73. $value_array['explog_memberid'] = $insertarr['explog_memberid'];
  74. $value_array['explog_membername'] = $insertarr['explog_membername'];
  75. $value_array['explog_points'] = $insertarr['explog_points'];
  76. $value_array['explog_addtime'] = TIMESTAMP;
  77. $value_array['explog_desc'] = $insertarr['explog_desc'];
  78. $value_array['explog_stage'] = $stage;
  79. $result = false;
  80. if ($value_array['explog_points'] != '0') {
  81. $result = self::addExppointslog($value_array);
  82. }
  83. if ($result) {
  84. //更新member内容
  85. $obj_member = model('member');
  86. $upmember_array = array();
  87. $upmember_array['member_exppoints'] = Db::raw('member_exppoints+'.$insertarr['explog_points']);
  88. $obj_member->editMember(array('member_id' => $insertarr['explog_memberid']), $upmember_array,$insertarr['explog_memberid']);
  89. return true;
  90. } else {
  91. return false;
  92. }
  93. }
  94. /**
  95. * 添加经验值日志信息
  96. * @access public
  97. * @author csdeshang
  98. * @param array $data 添加信息数组
  99. * @return array
  100. */
  101. public function addExppointslog($data) {
  102. if (empty($data)) {
  103. return false;
  104. }
  105. $result = Db::name('exppointslog')->insertGetId($data);
  106. return $result;
  107. }
  108. /**
  109. * 经验值日志总条数
  110. * @access public
  111. * @author csdeshang
  112. * @param array $where 条件数组
  113. * @param string $field 查询字段
  114. * @return int
  115. */
  116. public function getExppointslogCount($where, $field = '*') {
  117. $count = Db::name('exppointslog')->field($field)->where($where)->count();
  118. return $count;
  119. }
  120. /**
  121. * 经验值日志列表
  122. * @access public
  123. * @author csdeshang
  124. * @param array $where 条件数组
  125. * @param string $field 查询字段
  126. * @param int $pagesize 分页信息
  127. * @param string $order 排序
  128. * @return array
  129. */
  130. public function getExppointslogList($where, $field = '*', $pagesize = 0, $order = '') {
  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. $stage_arr = array();
  148. $stage_arr['login'] = '会员登录';
  149. $stage_arr['comments'] = '商品评论';
  150. $stage_arr['order'] = '订单消费';
  151. $stage_arr['system'] = '系统调整';
  152. return $stage_arr;
  153. }
  154. }
  155. ?>