Points.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. /**
  3. * 积分
  4. */
  5. namespace app\common\model;
  6. use think\facade\Db;
  7. /**
  8. * ============================================================================
  9. * DSMall多用户商城
  10. * ============================================================================
  11. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  12. * 网站地址: http://www.csdeshang.com
  13. * ----------------------------------------------------------------------------
  14. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  15. * 不允许对程序代码以任何形式任何目的的再发布。
  16. * ============================================================================
  17. * 数据层模型
  18. */
  19. class Points extends BaseModel {
  20. public $page_info;
  21. /**
  22. * 操作积分
  23. * @access public
  24. * @author csdeshang
  25. * @param string $stage 操作阶段 regist(注册),login(登录),comments(评论),order(下单),system(系统),other(其他),pointorder(积分礼品兑换),app(同步积分兑换)
  26. * @param array $insertarr 该数组可能包含信息 array('pl_memberid'=>'会员编号','pl_membername'=>'会员名称','pl_adminid'=>'管理员编号','pl_adminname'=>'管理员名称','pl_points'=>'积分','pl_desc'=>'描述','orderprice'=>'订单金额','order_sn'=>'订单编号','order_id'=>'订单序号','point_ordersn'=>'积分兑换订单编号');
  27. * @param bool $if_repeat 是否可以重复记录的信息,true可以重复记录,false不可以重复记录,默认为true
  28. * @return bool
  29. */
  30. function savePointslog($stage, $insertarr, $if_repeat = true) {
  31. if (!$insertarr['pl_memberid']) {
  32. return false;
  33. }
  34. //记录原因文字
  35. switch ($stage) {
  36. case 'regist':
  37. if (!isset($insertarr['pl_desc'])) {
  38. $insertarr['pl_desc'] = '注册会员';
  39. }
  40. $insertarr['pl_points'] = intval(config('ds_config.points_reg'));
  41. break;
  42. case 'login':
  43. if (!isset($insertarr['pl_desc'])) {
  44. $insertarr['pl_desc'] = '会员登录';
  45. }
  46. $insertarr['pl_points'] = intval(config('ds_config.points_login'));
  47. break;
  48. case 'comments':
  49. if (!isset($insertarr['pl_desc'])) {
  50. $insertarr['pl_desc'] = '评论商品';
  51. }
  52. $insertarr['pl_points'] = intval(config('ds_config.points_comments'));
  53. break;
  54. case 'order':
  55. if (!isset($insertarr['pl_desc'])) {
  56. $insertarr['pl_desc'] = '订单' . $insertarr['order_sn'] . '购物消费';
  57. }
  58. $insertarr['pl_points'] = 0;
  59. if ($insertarr['orderprice']) {
  60. $insertarr['pl_points'] = @intval($insertarr['orderprice'] / config('ds_config.points_orderrate'));
  61. if ($insertarr['pl_points'] > intval(config('ds_config.points_ordermax'))) {
  62. $insertarr['pl_points'] = intval(config('ds_config.points_ordermax'));
  63. }
  64. }
  65. //订单添加赠送积分列
  66. $obj_order = model('order');
  67. $data = array();
  68. $data['order_pointscount'] = Db::raw('order_pointscount+'.$insertarr['pl_points']);
  69. $obj_order->editOrdercommon($data, array('order_id' => $insertarr['order_id']));
  70. break;
  71. case 'system':
  72. case 'gift':
  73. break;
  74. case 'pointorder':
  75. if (!isset($insertarr['pl_desc'])) {
  76. $insertarr['pl_desc'] = '兑换礼品信息' . $insertarr['point_ordersn'] . '消耗积分';
  77. }
  78. break;
  79. case 'app':
  80. if (!isset($insertarr['pl_desc'])) {
  81. $insertarr['pl_desc'] = lang('points_pointorderdesc_app');
  82. }
  83. break;
  84. case 'signin':
  85. if (!isset($insertarr['pl_desc'])) {
  86. $insertarr['pl_desc'] = '签到得到积分';
  87. }
  88. break;
  89. case 'inviter':
  90. if (!isset($insertarr['pl_desc'])) {
  91. $insertarr['pl_desc'] = '邀请新会员[' . $insertarr['invited'] . ']注册';
  92. }
  93. $insertarr['pl_points'] = intval(config('ds_config.points_invite'));
  94. break;
  95. case 'rebate':
  96. if (!isset($insertarr['pl_desc'])) {
  97. $insertarr['pl_desc'] = '邀请人消费得到积分';
  98. }
  99. break;
  100. case 'marketmanage':
  101. break;
  102. case 'other':
  103. break;
  104. }
  105. $save_sign = true;
  106. if ($if_repeat == false) {
  107. //检测是否有相关信息存在,如果没有,入库
  108. $condition = array();
  109. $condition[] = array('pl_memberid','=',$insertarr['pl_memberid']);
  110. $condition[] = array('pl_stage','=',$stage);
  111. $log_array = self::getPointsInfo($condition);
  112. if (!empty($log_array)) {
  113. $save_sign = false;
  114. }
  115. }
  116. if ($save_sign == false) {
  117. return true;
  118. }
  119. //新增日志
  120. $value_array = array();
  121. $value_array['pl_memberid'] = $insertarr['pl_memberid'];
  122. $value_array['pl_membername'] = $insertarr['pl_membername'];
  123. if (isset($insertarr['pl_adminid'])) {
  124. $value_array['pl_adminid'] = $insertarr['pl_adminid'];
  125. }
  126. if (isset($insertarr['pl_adminname'])) {
  127. $value_array['pl_adminname'] = $insertarr['pl_adminname'];
  128. }
  129. $value_array['pl_points'] = $insertarr['pl_points'];
  130. $value_array['pl_addtime'] = TIMESTAMP;
  131. $value_array['pl_desc'] = $insertarr['pl_desc'];
  132. $value_array['pl_stage'] = $stage;
  133. $result = false;
  134. if ($value_array['pl_points'] != '0') {
  135. $result = self::addPointslog($value_array);
  136. }
  137. if ($result) {
  138. //更新member内容
  139. $obj_member = model('member');
  140. $upmember_array = array();
  141. $upmember_array['member_points'] = Db::raw('member_points+'.$insertarr['pl_points']);
  142. $obj_member->editMember(array('member_id' => $insertarr['pl_memberid']), $upmember_array,$insertarr['pl_memberid']);
  143. return true;
  144. } else {
  145. return false;
  146. }
  147. }
  148. /**
  149. * 添加积分日志信息
  150. * @access public
  151. * @author csdeshang
  152. * @param type $data 数据
  153. * @return boolean
  154. */
  155. public function addPointslog($data) {
  156. if (empty($data)) {
  157. return false;
  158. }
  159. $result = Db::name('pointslog')->insertGetId($data);
  160. return $result;
  161. }
  162. /**
  163. * 积分日志列表
  164. * @access public
  165. * @author csdeshang
  166. * @param type $condition
  167. * @param type $pagesize
  168. * @param type $field
  169. * @return type
  170. */
  171. public function getPointslogList($condition, $pagesize = '', $field = '*',$limit=0,$order='pl_addtime desc') {
  172. if ($pagesize) {
  173. $result = Db::name('pointslog')->where($condition)->field($field)->order($order)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  174. $this->page_info = $result;
  175. return $result->items();
  176. } else {
  177. return Db::name('pointslog')->where($condition)->field($field)->limit($limit)->order($order)->select()->toArray();
  178. }
  179. }
  180. /**
  181. * 积分日志详细信息
  182. * @access public
  183. * @author csdeshang
  184. * @param type $condition
  185. * @param type $field
  186. * @return type
  187. */
  188. public function getPointsInfo($condition, $field = '*') {
  189. //得到条件语句
  190. return Db::name('pointslog')->field($field)->where($condition)->find();
  191. }
  192. /**
  193. *
  194. */
  195. public function getPointsCount($condition) {
  196. return Db::name('pointslog')->where($condition)->count();
  197. }
  198. }