Points.php 8.1 KB

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