SHOPNC 添加一元云购模块

其他不说了,先上效果图

首页效果图

QQ图片20160828200930.png

列表页效果图:

QQ截图20160828201136.png

详情页效果图:

 

QQ截图20160828201249.png

后台效果:

QQ图片20160828201838.png

后台效果图2:

QQ截图20160828202037.png

相关代码

新国数据表

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

CREATE TABLE `tp_cloud_goods` (

  `cgoods_id` int(10) unsigned NOT NULL AUTO_INCREMENT,

  `store_id` int(10) DEFAULT '0' COMMENT '商家id',

  `gc_id` int(10) unsigned NOT NULL COMMENT '商品分类id',

  `gc_id_1` int(10) unsigned NOT NULL COMMENT '一级分类id',

  `gc_id_2` int(10) unsigned NOT NULL COMMENT '二级分类id',

  `gc_id_3` int(10) unsigned NOT NULL COMMENT '三级分类id',

  `gc_name` varchar(200) NOT NULL COMMENT '商品分类',

  `brand_id` int(10) unsigned DEFAULT '0' COMMENT '品牌id',

  `brand_name` varchar(200) DEFAULT NULL COMMENT '品牌名字',

  `city_id` int(10) DEFAULT '0',

  `area_id` int(10) DEFAULT '0',

  `sell_id` int(10) DEFAULT '0' COMMENT '店铺ID(不是自宫店的)',

  `type` tinyint(1) DEFAULT '0' COMMENT '类型 1=1元云购,2=5元云购,3=10元云购',

  `title` varchar(64) DEFAULT '' COMMENT '产品名称',

  `intro` varchar(255) DEFAULT '' COMMENT '产品简介',

  `body` text COMMENT '商品详情',

  `mobile_body` text NOT NULL COMMENT '手机端商品描述',

  `joins` int(10) DEFAULT '0' COMMENT '已购买数量',

  `price` int(10) DEFAULT '0' COMMENT '总需人次',

  `mk_price` decimal(10,2) DEFAULT '0.00' COMMENT '市场价',

  `maxint(10) DEFAULT '0' COMMENT '单人最大购买次数',

  `settlement_price` int(10) DEFAULT '0' COMMENT '结算价格(扣除用户积分数量=数量*结算价格)',

  `photo` varchar(128) DEFAULT '' COMMENT '商品组图',

  `thumb` text COMMENT '缩略图',

  `is_hot` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '商品推荐 1是,0否 默认0',

  `status` tinyint(4) DEFAULT '1' COMMENT '状态 1=正在进行 3=正在揭晓 4=已结束',

  `color_id` int(10) DEFAULT '0' COMMENT '颜色ID',

  `win_user_name` varchar(30) DEFAULT NULL COMMENT '获奖用户名',

  `win_user_id` int(10) DEFAULT '0' COMMENT '中奖人',

  `win_number` int(10) DEFAULT '0' COMMENT '中奖号',

  `closed` tinyint(1) DEFAULT '0' COMMENT '1删除状态 0 正常',

  `audit` tinyint(1) DEFAULT '1' COMMENT '审核 1审核通过 0未审核',

  `lottery_time` int(10) DEFAULT '0' COMMENT '中奖时间',

  `goods_selltime` int(10) DEFAULT '0' COMMENT '开始时间,当status=2时需要判断这个时间是否大于当前时间',

  `create_time` int(10) DEFAULT '0' COMMENT '添加时间',

  `goods_edittime` int(11) DEFAULT '0' COMMENT '更新时间',

  `create_ip` char(11) DEFAULT '' COMMENT '添加IP',

  `adress` varchar(1024) DEFAULT NULL,

  PRIMARY KEY (`cgoods_id`)

) ENGINE=InnoDB AUTO_INCREMENT=100002 DEFAULT CHARSET=utf8 COMMENT='云购商品';

CREATE TABLE `tp_cloud_logs` (

  `log_id` int(10) unsigned NOT NULL AUTO_INCREMENT,

  `cgoods_id` int(10) DEFAULT '0' COMMENT '云购商品ID',

  `user_id` int(10) DEFAULT '0' COMMENT '用户ID',

  `num` int(10) DEFAULT '0' COMMENT '购买数量',

  `create_time` int(10) DEFAULT '0' COMMENT '添加时间',

  `microtime` varchar(3) DEFAULT '0',

  `create_ip` varchar(15) DEFAULT '',

  PRIMARY KEY (`log_id`)

) ENGINE=InnoDB AUTO_INCREMENT=52 DEFAULT CHARSET=utf8 COMMENT='云购商品购买记录表';

CREATE TABLE `tp_cloud_goods` (

  `cgoods_id` int(10) unsigned NOT NULL AUTO_INCREMENT,

  `store_id` int(10) DEFAULT '0' COMMENT '商家id',

  `gc_id` int(10) unsigned NOT NULL COMMENT '商品分类id',

  `gc_id_1` int(10) unsigned NOT NULL COMMENT '一级分类id',

  `gc_id_2` int(10) unsigned NOT NULL COMMENT '二级分类id',

  `gc_id_3` int(10) unsigned NOT NULL COMMENT '三级分类id',

  `gc_name` varchar(200) NOT NULL COMMENT '商品分类',

  `brand_id` int(10) unsigned DEFAULT '0' COMMENT '品牌id',

  `brand_name` varchar(200) DEFAULT NULL COMMENT '品牌名字',

  `city_id` int(10) DEFAULT '0',

  `area_id` int(10) DEFAULT '0',

  `sell_id` int(10) DEFAULT '0' COMMENT '店铺ID(不是自宫店的)',

  `type` tinyint(1) DEFAULT '0' COMMENT '类型 1=1元云购,2=5元云购,3=10元云购',

  `title` varchar(64) DEFAULT '' COMMENT '产品名称',

  `intro` varchar(255) DEFAULT '' COMMENT '产品简介',

  `body` text COMMENT '商品详情',

  `mobile_body` text NOT NULL COMMENT '手机端商品描述',

  `joins` int(10) DEFAULT '0' COMMENT '已购买数量',

  `price` int(10) DEFAULT '0' COMMENT '总需人次',

  `mk_price` decimal(10,2) DEFAULT '0.00' COMMENT '市场价',

  `maxint(10) DEFAULT '0' COMMENT '单人最大购买次数',

  `settlement_price` int(10) DEFAULT '0' COMMENT '结算价格(扣除用户积分数量=数量*结算价格)',

  `photo` varchar(128) DEFAULT '' COMMENT '商品组图',

  `thumb` text COMMENT '缩略图',

  `is_hot` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '商品推荐 1是,0否 默认0',

  `status` tinyint(4) DEFAULT '1' COMMENT '状态 1=正在进行 3=正在揭晓 4=已结束',

  `color_id` int(10) DEFAULT '0' COMMENT '颜色ID',

  `win_user_name` varchar(30) DEFAULT NULL COMMENT '获奖用户名',

  `win_user_id` int(10) DEFAULT '0' COMMENT '中奖人',

  `win_number` int(10) DEFAULT '0' COMMENT '中奖号',

  `closed` tinyint(1) DEFAULT '0' COMMENT '1删除状态 0 正常',

  `audit` tinyint(1) DEFAULT '1' COMMENT '审核 1审核通过 0未审核',

  `lottery_time` int(10) DEFAULT '0' COMMENT '中奖时间',

  `goods_selltime` int(10) DEFAULT '0' COMMENT '开始时间,当status=2时需要判断这个时间是否大于当前时间',

  `create_time` int(10) DEFAULT '0' COMMENT '添加时间',

  `goods_edittime` int(11) DEFAULT '0' COMMENT '更新时间',

  `create_ip` char(11) DEFAULT '' COMMENT '添加IP',

  `adress` varchar(1024) DEFAULT NULL,

  PRIMARY KEY (`cgoods_id`)

) ENGINE=InnoDB AUTO_INCREMENT=100002 DEFAULT CHARSET=utf8 COMMENT='云购商品';

CREATE TABLE `tp_cloud_logs` (

  `log_id` int(10) unsigned NOT NULL AUTO_INCREMENT,

  `cgoods_id` int(10) DEFAULT '0' COMMENT '云购商品ID',

  `user_id` int(10) DEFAULT '0' COMMENT '用户ID',

  `num` int(10) DEFAULT '0' COMMENT '购买数量',

  `create_time` int(10) DEFAULT '0' COMMENT '添加时间',

  `microtime` varchar(3) DEFAULT '0',

  `create_ip` varchar(15) DEFAULT '',

  PRIMARY KEY (`log_id`)

) ENGINE=InnoDB AUTO_INCREMENT=50 DEFAULT CHARSET=utf8 COMMENT='云购商品购买记录表';

CREATE TABLE `tp_cloudgoods_images` (

  `goods_image_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '商品图片id',

  `cgoods_id` int(10) unsigned NOT NULL COMMENT '商品公共内容id',

  `store_id` int(10) unsigned NOT NULL COMMENT '商家id',

  `color_id` int(10) unsigned NOT NULL COMMENT '颜色规格值id',

  `goods_image` varchar(1000) NOT NULL COMMENT '商品图片',

  `goods_image_sort` tinyint(3) unsigned NOT NULL COMMENT '排序',

  `is_default` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '默认主题,1是,0否',

  PRIMARY KEY (`goods_image_id`)

) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8 COMMENT='商品图片';

核心代码:

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

//云购商品类别

    public function getType() {

        return array(

            '1' => array(

                'type_name' => '1元云购',

                'num' => 1,

            ),

            '2' => array(

                'type_name' => '5元云购',

                'num' => 5,

            ),

            '3' => array(

                'type_name' => '10元云购',

                'num' => 10,

            ),

        );

    }

     

    //购云商品

    public function Buy_cloud($goods_id$user_id$num){

        $detail $this->getGoodsInfo(array('cgoods_id' => $goods_id));

        if($detail['sell_id'] != '0'){

            //只有在店消费才可以参与

            $paycount $this->table('store_rechargelog')->where(array('lg_store_id'=>$detail['sell_id'],'lg_member_id'=>$user_id))->count();

            if($paycount<1){

                return array('status'=>'0','msg'=>'你没有资格参与此云购商品');

            }

        }

        //判断买数量

        $lefts $detail['price'] - $detail['joins'];

        if ($num $lefts) {

            return array('status'=>'0','msg'=>'数量不足');

        }

        $member_info = Model('member')->getMemberInfoByID($user_id);

        if ($num $detail['settlement_price'] > $member_info['available_predeposit']) {

            return array('status'=>'0','msg'=>'用户积分不足');

        }

         

        $count $this->table('cloud_logs')->where(array('cgoods_id' => $goods_id'user_id' => $user_id))->count();

        $left $detail['max'] - $count;

        //单用户最大购买数量

        if ($num $left) {

            return array('status'=>'0','msg'=>'超出单用户最大购买数量');

        }

        $t = microtime(false);

        $tt substr($t, 0, 5);

        $microtime round($tt, 3) * 1000;

        if (!$microtime || $microtime == NULL || empty($microtime)) {

            $microtime = 000;

        }

        if (strlen($microtime) == 0) {

            $microtime = 000;

        elseif (strlen($microtime) == 1) {

            $microtime '00' $microtime;

        elseif (strlen($microtime) == 2) {

            $microtime '0' $microtime;

        }

     

        $newjoins  = (int)$detail['joins'] + $num;

        $model_prede = Model('predeposit');

        try {

            $model_prede->beginTransaction();

             

            $log_id $model_prede->addCloud_logs(array('cgoods_id'=>$goods_id,'user_id'=>$user_id,'num'=>$num,'create_time'=>time(),'microtime' => $microtime));

             

            $arr array(

                'invite_member_id'=>0,

                'member_id'=>$user_id,

                'member_name'=>$member_info['member_name'],

                'amount'=>$num $detail['settlement_price'],//消费积分数量

                'log_id'=>$log_id,//购买记录ID

            );

            $model_prede->changePd('cgoods_del_money',$arr);//消费积分变更及记录

            $model_prede->editCloud_cgoods(array('cgoods_id'=>$goods_id),array('joins'=>$newjoins));//加一条已购买的

             

            $model_prede->commit();

             

        catch (Exception $e) {

            $model_prede->rollback();

            return array('status'=>'0','msg'=>'哎呀,出错啦'.$e->getMessage());

        }

        if($detail['price'] <= $newjoins){

            $this->table('cloud_goods')->where(array('cgoods_id'=>$goods_id))->update(array('status'=>3));//修改状态为待揭晓

            //$this->lottery( $goods_id );//自动处理中奖(改为手动开奖)

        }

        return array('status'=>'1','msg'=>'购买成功');

    }

    //处理中奖

    public function lottery($goods_id){

        $goods_id = (int) $goods_id;

        $detail $this->getGoodsInfo(array('cgoods_id' => $goods_id));

        if(!$detail){

            return false;

        }

        $res $this->table('cloud_logs')->where(array('cgoods_id'=>$goods_id))->order(array('log_id' => 'asc'))->select();

        $list $this->get_datas($res);

        $return $this->get_last50_time($res);

        $zhongjiang fmod($return['total'],$detail['price'])  + 10000001;

        $member_info = Model('member')->getMemberInfo(array('member_id'=>$list[$zhongjiang]['user_id']),'*');

        if($this->table('cloud_goods')->where(array('cgoods_id'=>$goods_id))->update(array('win_user_name'=>$member_info['member_name'],'win_user_id'=>$list[$zhongjiang]['user_id'],'win_number'=>$list[$zhongjiang]['number'],'status'=>4,'lottery_time'=>time()))){

            return true;

        }else{

            return false;

        }

    }

    public function get_datas($datas) {

        $return array();

        $i = 0;

        foreach ($datas as $val) {

             

            $val['member_mobile'] = substr($val['member_mobile'],0,3).'****'.substr($val['member_mobile'],-4);

            $data $val;

            for ($a = 0; $a $val['num']; $a++) {

                $num = 10000001 + $i;

                $data['number'] = $num;

                $return[$num] = $data;

                $i++;

            }

        }

        krsort($return);

        return $return;

    }

    public function get_last50_time($data) {

        $return array('total' => 0, 'datas' => array());

        $i = 0;

        //krsort($data);

        foreach ($data as $val) {

            for ($a = 0; $a $val['num']; $a++) {

                $user_time intval(date('His',$val['create_time']).$val['microtime']);

                if ($i < 50) {

                    $return['total']+= $user_time;

                    $return['datas'][] = $val;

                else

                    break;

                $i++;

            }

        }

        krsort($return['datas']);

        return $return;

    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值