chengkun
2025-04-18 1bb985f32f2efe0f9dd69f3cf29a1c809b1cf96d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
<?php
/*
* $Author :PHPYUN开发团队
*
* 官网: http://www.phpyun.com
*
* 版权所有 2009-2021 宿迁鑫潮信息技术有限公司,并保留所有权利。
*
* 软件声明:未经授权前提下,不得用于商业运营、二次开发以及任何形式的再次发布。
 */
class redeem_model extends model
{
    /**
     * @desc   引用log类,添加用户日志   
     */
    private function addMemberLog($uid,$usertype,$content,$opera='',$type='') {
        require_once ('log.model.php');
        $LogM = new log_model($this->db, $this->def);
        return  $LogM -> addMemberLog($uid,$usertype,$content,$opera='',$type=''); 
    }
    //查询单条商品
    function getInfo($where=array(),$data=array()){
        
        $data['field']  =    empty($data['field']) ? '*' : $data['field'];
        
        $info    =    $this -> select_once('reward',$where,$data['field']);
        if(!empty($info)){
            if($info['pic']){
                $info['pic']    = checkpic($info['pic']);
            }
            if($info['content']){
                $content=htmlspecialchars_decode($info['content']);
                $info['content_n'] = $content;
                preg_match_all('/<img(.*?)src=("|\'|\s)?(.*?)(?="|\'|\s)/',$content,$res);
                if(!empty($res[3])){
                    foreach($res[3] as $v){
                        if(strpos($v,'http:')===false && strpos($v,'https:')===false){
                            $ossv                 = checkpic($v);
                            $info['content_n'] = str_replace($v,$ossv,$content);
                        }
                    }
                }
            }
        }
        return $info;
    }
 
    //查询商品列表
    function getList($whereData,$data=array()){
        
        $data['field']  =    empty($data['field']) ? '*' : $data['field'];
        
        $List            =    $this->select_all("reward",$whereData,$data['field']);
        
        if(!empty( $List )){
            
            foreach($List as $key=>$val){
                $nids[]         =     $val['nid'];
                $tnids[]         =     $val['tnid'];
            }
            
            $classWhere['id']    =    array('>',0);
            $class                =    $this->select_all("redeem_class",$classWhere);
            
            $classname='';
            foreach($List as $k=>$v){
                foreach($class as $val){
                    if($v['nid']==$val['id']){
                        $classname            =    $val['name'];
                    }
                    
                    if($v['tnid']==$val['id']){
                        $classname            =    $List[$k]['classname'].'-'.$val['name'];
                    }
                    
                    $List[$k]['classname']    =    $classname;
                }
            }
        }
        
        return $List;
    }
    
    function upInfo($data = array(),$whereData)
    {
        if(!empty($whereData)){
            $nid    =    $this -> update_once('reward',$data,$whereData);
        }
        return $nid;
    }
 
    function delReward($whereData,$data){
        
        if($data['type']=='one'){//单个删除
            
            $limit    =    'limit 1';
        }
        
        if($data['type']=='all'){//多个删除
        
            $limit    =    '';
        }
        
        $result    =    $this    ->    delete_all('reward',$whereData,$limit);
        
        return    $result;
        
    }
 
    function addInfo($setData){
 
        if(!empty($setData)){
            
            $nid    =    $this -> insert_into('reward',$setData);
            
        }
 
        return $nid;
    }
    function getChangeList($whereData,$data=array()){
        $ListNew        =    array();
        $data['field']  =    empty($data['field']) ? '*' : $data['field'];
        $List            =    $this -> select_all('change',$whereData,$data['field']);
        
        if(!empty( $List )){
            
            $gid  =   array();
            
            foreach($List as $key=>$val){
            
                $gid[]   =   $val['gid'];
 
            }
            
            require_once ('redeem.model.php');
            $redeemM     =   new redeem_model($this->db, $this->def);
            $gift        =   $redeemM->getList(array('id'=>array('in',pylode(',', $gid))),array('field'=>'id,pic'));
            
            $dh = $sh = $wtg =0;
            foreach($List as $key=>$val){
                $List[$key]['wapredeem_url'] = Url('wap',array('c'=>'redeem','a'=>'show','id'=>$val['gid']));
                $List[$key]['ctime_n'] = date('Y-m-d h:i',$val['ctime']);
                if($val['body']){
                    $List[$key]['address'] = mb_substr($val['body'],5,-1);
                }else{
                    $List[$key]['address']="";
                }
                foreach ($gift as $v){
                    if($val['gid']==$v['id']){
                        $List[$key]['pic']    =    checkpic($v['pic'],$this->config['sy_imgsc_mr']);
                    }
                }
                
                if($data['utype']=='wap'){
                    
                    
                    if($val['status']==0){
                        $sh   =   $sh + 1;
                    }
                    
                    if($val['status']==2){
                        $wtg  =   $wtg + 1;
                    }
                    if($val['status']==1){
                        $dh   =   $dh + 1;
                    }        
                }
            }
            $ListNew['dh']        =    $dh;
            $ListNew['wtg']        =    $wtg;
            $ListNew['sh']        =    $sh;
            $ListNew['list']    =    $List;
            
        }
 
        return    $ListNew;
    }
    
    function getChangeInfo($whereData, $data = array()){
        
        if($whereData){
            $data['field']  =    empty($data['field']) ? '*' : $data['field'];
        
            $List    =    $this -> select_once('change',$whereData,$data['field']);
        }
 
        return $List;
    
    }
    function AddChange($data = array()){
        $num    =    (int)$data['num'];
        $id        =    (int)$data['id'];
        
        $info        =    $this->select_once('member',array("uid"=>$data['uid']),'`password`,`salt`');
        
        require_once ('statis.model.php');
        $statisM     =     new statis_model($this->db, $this->def);
        $statis        =    $statisM->getInfo($data['uid'],array("usertype"=>$data['usertype'],"field"=>"`integral`"));
        
        $gift        =    $this->getInfo(array("id"=>(int)$data['id']));
        
        $nums        =    $this->select_num('change',array("gid"=>$gift['id'],"uid"=>$data['uid']));
        
        $integral    =    $gift['integral']*$num;
        
        if(!$data['uid'] && !$data['username']){
            $return['msg']        =    '您还没有登录,请先登录!';
            $return['errcode']        =    '8';
        }elseif(!$data['linkman'] || !$data['linktel'] ){
            $return['msg']        =    '收件人和手机号码不能为空!';
            $return['errcode']        =    '8';
        }elseif($data['linktel']&&CheckMobile($data['linktel'])==false){
            $return['msg']        =    '手机格式错误!';
            $return['errcode']        =    '8';
        }elseif(!$data['password']){
            $return['msg']        =    '密码不能为空!';
            $return['errcode']        =    '8';
        }elseif(!passCheck($data['password'],$info['salt'],$info['password'])){
            $return['msg']        =    '用户名或密码不正确!';
            $return['errcode']        =    '8';
        }elseif($num<1){
            $return['msg']        =    '请填写正确的数量!';
            $return['errcode']        =    '8';
        }elseif($num>$gift['stock']){
            $return['msg']        =    '已超出库存数量!';
            $return['errcode']        =    '8';
        }elseif($gift['restriction']!='0' && $nums+$num>$gift['restriction']){
            $return['msg']        =    '已超出限购数量!';
            $return['errcode']        =    '8';
        }elseif($statis['integral']<$integral){
            $return['msg']        =    '您的'.$this->config['integral_pricename'].'不足!';
            $return['errcode']        =    '8';
        }else{
            require_once ('integral.model.php');
            $integralM = new integral_model($this->db, $this->def);
            //积分操作记录
            $integralM->company_invtal($data['uid'],$data['usertype'],$integral,false,"".$this->config['integral_pricename']."兑换",true,2,'integral',24);
      if($data['bodyt']){
         $data['body']=$data['bodyt'];
      }else{
        $data['body']='收货地址:'.$data['provinceid'].' '.$data['cityid'].' '.$data['three_cityid'];
        if($data['address']){
          $data['body'].=' '.$data['address'];
        }
        if($data['other']){
          $data['body'].=' 用户留言:'.$data['other'];
        }
      }
 
 
            $post=array(
                'uid'        =>    $data['uid'],
                'username'    =>    $data['username'],
                'usertype'    =>    $data['usertype'],
                'name'        =>    $gift['name'],
                'gid'        =>    $gift['id'],
                'linkman'    =>    $data['linkman'],
                'linktel'    =>    $data['linktel'],
                'body'        =>    $data['body'],
                'integral'    =>    $integral,
                'num'        =>    $num,
                'ctime'        =>    time()
            );
            $this->insert_into('change',$post);
            
            $this->update_once('reward',array('num'=>array('+',$num),'stock'=>array('-',$num)),array("id"=>$data['id']));
            
            $this -> addMemberLog($data['uid'], $data['usertype'],$this->config['integral_pricename']."兑换,商品ID:".$gift['id'],17,1);
            
            require_once('admin.model.php');
            $adminM = new admin_model($this->db,$this->def);
 
            $adminM->sendAdminMsg(array(
                'first'=>'有新的商品兑换需要审核,用户《'.$data['username'].'》花费'.$integral.$this->config['integral_pricename'].'兑换了'.$num.'个'.$gift['name'].'。',
                'type'=>18
            ));
 
            $return['msg']='兑换成功,请等待管理员审核!';
            $return['errcode']='9';
            if($data['utype']=='pc'){
                $return['url']=Url('redeem',array('c'=>'show','id'=>$id));
            }
            if($data['utype']=='wap'){
                $return['url']=Url('wap',array('c'=>'redeem','a'=>'show','id'=>$id));
            }
        }
        return $return;
    }
 
    function getChangeNum($whereData, $data = array()){
        
        if($whereData){
            $data['field']  =    empty($data['field']) ? '*' : $data['field'];
        
            $List    =    $this -> select_num('change',$whereData,$data['field']);
        }
 
        return $List;
    
    }
 
    function addChangeInfo($setData){
 
        if(!empty($setData)){
            
            $nid    =    $this -> insert_into('change',$setData);
            
        }
 
        return $nid;
    
    }
 
    function upChangeInfo($whereData, $data = array()){
 
        if(!empty($whereData)){
            
            $nid    =    $this -> update_once('change',$data,$whereData);
            
        }
 
        return $nid;
    
    }
    
     function delChange($whereData,$data=array())
    {
        $limit = "";//多个删除
        if(!is_array($whereData['id'])){
            $limit  =  'limit 1';
        }
        
        /**$data['member']    :会员中心执行删除,member为user表示个人会员,com表示企业会员
        *  $data['uid']          :用户uid
        *  $data['usertype']:用户usertype
        *  $data['id']          :change表id
        */
 
        if($data['member']){
            if($data['uid']==''
                ||($data['member']=='com'&&$data['usertype']!='2')
                ||($data['member']=='user'&&$data['usertype']!='1')){
 
                $result['msg']    =    '登录超时';
                $result['cod']    =    8;
            }else{
                $rows    =    $this    ->    getChangeInfo(array('uid'=>$data['uid'],'id'=>$data['id']));
                if($rows['id']){
                    require_once('integral.model.php');
                    $IntegralM    =    new integral_model($this->db,$this->def);
                    
                    $this    ->    update_once('reward',array('num'=>array('-',$rows['num']),'stock'=>array('+',$rows['num'])),array('id'=>$rows['gid']));
 
                    $IntegralM    ->    company_invtal($data['uid'],$data['usertype'],$rows['integral'],true,"取消商品兑换",true,2,'integral',24);
                    $this        ->    delete_all('change',array('uid'=>$data['uid'],'id'=>$data['id']),$limit);
                }
                $this    ->    addMemberLog($data['uid'],$data['usertype'],"取消兑换",17,3);//会员日志
                $result['msg']    =    '取消成功!';
                $result['cod']    =    9;
            }
        }else{
            $result    =    $this -> delete_all('change',$whereData,$limit);
        }
        
        return    $result;
        
    }
    //************************end************************
    
 
    //*********************redeem_class******************
    //查询商品分类
    function GetRewardClass($whereData,$data=array()){
        $ListNew        =    array();
        $data['field']  =    empty($data['field']) ? '*' : $data['field'];
        $List            =    $this -> select_all('redeem_class',$whereData,$data['field']);
        
        if(!empty( $List )){
            
            $ListNew['list']    =    $List;
        }
 
        return    $ListNew;
        
    }
    
    function getRedeemClassInfo($whereData, $data = array()){
        
        if($whereData){
            $data['field']  =    empty($data['field']) ? '*' : $data['field'];
        
            $List    =    $this -> select_once('redeem_class',$whereData,$data['field']);
        }
 
        return $List;
    
    }
 
    function addRedeemClassInfo($setData){
 
        if(!empty($setData)){
            
            $nid    =    $this -> insert_into('redeem_class',$setData);
            
        }
 
        return $nid;
    
    }
 
    function upRedeemClassInfo($whereData, $data = array()){
 
        if(!empty($whereData)){
            
            $nid    =    $this -> update_once('redeem_class',$data,$whereData);
            
        }
 
        return $nid;
    
    }
    
    
    function delRedeemClass($whereData,$data){
        
        if($data['type']=='one'){//单个删除
            
            $limit        =    'limit 1';
            
        }
        
        if($data['type']=='all'){//多个删除
        
            $limit        =    '';
            
        }
        
        $result            =    $this    ->    delete_all('redeem_class',$whereData,$limit);
        
        return    $result;
        
    }
    //************************end************************
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}
?>