123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- <?php
- namespace app\common\model;
- use think\facade\Db;
- class Points extends BaseModel
- {
- public $page_info;
-
- function savePointslog($stage, $insertarr, $if_repeat = true)
- {
- if (!$insertarr['pl_memberid']) {
- return false;
- }
-
- switch ($stage) {
- case 'regist':
- if (!isset($insertarr['pl_desc'])) {
- $insertarr['pl_desc'] = '注册会员';
- }
- $insertarr['pl_points'] = intval(config('ds_config.points_reg'));
- break;
- case 'login':
- if (!isset($insertarr['pl_desc'])) {
- $insertarr['pl_desc'] = '会员登录';
- }
- $insertarr['pl_points'] = intval(config('ds_config.points_login'));
- break;
- case 'comments':
- if (!isset($insertarr['pl_desc'])) {
- $insertarr['pl_desc'] = '评论商品';
- }
- $insertarr['pl_points'] = intval(config('ds_config.points_comments'));
- break;
- case 'order':
- if (!isset($insertarr['pl_desc'])) {
- $insertarr['pl_desc'] = '订单' . $insertarr['order_sn'] . '购物消费';
- }
- $insertarr['pl_points'] = 0;
- if ($insertarr['orderprice']) {
- $insertarr['pl_points'] = @intval($insertarr['orderprice'] / config('ds_config.points_orderrate'));
- if ($insertarr['pl_points'] > intval(config('ds_config.points_ordermax'))) {
- $insertarr['pl_points'] = intval(config('ds_config.points_ordermax'));
- }
- }
-
- $obj_order = model('order');
- $data = array();
- $data['order_pointscount'] = Db::raw('order_pointscount+' . $insertarr['pl_points']);
- $obj_order->editOrdercommon($data, array('order_id' => $insertarr['order_id']));
- break;
- case 'system':
- case 'gift':
- break;
- case 'pointorder':
- if (!isset($insertarr['pl_desc'])) {
- $insertarr['pl_desc'] = '兑换礼品信息' . $insertarr['point_ordersn'] . '消耗积分';
- }
- break;
- case 'app':
- if (!isset($insertarr['pl_desc'])) {
- $insertarr['pl_desc'] = lang('points_pointorderdesc_app');
- }
- break;
- case 'signin':
- if (!isset($insertarr['pl_desc'])) {
- $insertarr['pl_desc'] = '签到得到积分';
- }
- break;
- case 'inviter':
- if (!isset($insertarr['pl_desc'])) {
- $insertarr['pl_desc'] = '邀请新会员[' . $insertarr['invited'] . ']注册';
- }
- $insertarr['pl_points'] = intval(config('ds_config.points_invite'));
- break;
- case 'rebate':
- if (!isset($insertarr['pl_desc'])) {
- $insertarr['pl_desc'] = '邀请人消费得到积分';
- }
- break;
- case 'marketmanage':
- break;
- case 'other':
- break;
- }
- $save_sign = true;
- if ($if_repeat == false) {
-
- $condition = array();
- $condition[] = array('pl_memberid', '=', $insertarr['pl_memberid']);
- $condition[] = array('pl_stage', '=', $stage);
- $log_array = self::getPointsInfo($condition);
- if (!empty($log_array)) {
- $save_sign = false;
- }
- }
- if ($save_sign == false) {
- return true;
- }
-
- $value_array = array();
- $value_array['pl_memberid'] = $insertarr['pl_memberid'];
- $value_array['pl_membername'] = $insertarr['pl_membername'];
- if (isset($insertarr['pl_adminid'])) {
- $value_array['pl_adminid'] = $insertarr['pl_adminid'];
- }
- if (isset($insertarr['pl_adminname'])) {
- $value_array['pl_adminname'] = $insertarr['pl_adminname'];
- }
- $value_array['pl_points'] = $insertarr['pl_points'];
- $value_array['pl_addtime'] = TIMESTAMP;
- $value_array['pl_desc'] = $insertarr['pl_desc'];
- $value_array['pl_stage'] = $stage;
- $result = false;
- if ($value_array['pl_points'] != '0') {
- $result = self::addPointslog($value_array);
- }
- if ($result) {
-
- $obj_member = model('member');
- $upmember_array = array();
- $upmember_array['member_points'] = Db::raw('member_points+' . $insertarr['pl_points']);
- $obj_member->editMember(array('member_id' => $insertarr['pl_memberid']), $upmember_array, $insertarr['pl_memberid']);
- return true;
- } else {
- return false;
- }
- }
-
- public function addPointslog($data)
- {
- if (empty($data)) {
- return false;
- }
- $result = Db::name('pointslog')->insertGetId($data);
- return $result;
- }
-
- public function getPointslogList($condition, $pagesize = '', $field = '*', $limit = 0, $order = 'pl_addtime desc')
- {
- if ($pagesize) {
- $result = Db::name('pointslog')->where($condition)->field($field)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
- $this->page_info = $result;
- return $result->items();
- } else {
- return Db::name('pointslog')->where($condition)->field($field)->limit($limit)->order($order)->select()->toArray();
- }
- }
-
- public function getPointsInfo($condition, $field = '*')
- {
-
- return Db::name('pointslog')->field($field)->where($condition)->find();
- }
-
- public function getPointsCount($condition)
- {
- return Db::name('pointslog')->where($condition)->count();
- }
- }
|