Exemplo n.º 1
0
 public function pay()
 {
     $credit = I('get.credit', 0, 'intval');
     $json = array('error' => 0, 'message' => '', 'data' => '');
     do {
         if ($credit < 1 || $credit > 999999) {
             $user = M('user')->find($this->user_id);
             $data['body'] = "用户充值";
             $data['attach'] = "用户充值";
             $data['order_sn'] = get_order_sn('TP');
             $data['total_fee'] = $credit * 10;
             $data['time_start'] = date('YmdHis');
             $data['time_expire'] = date("YmdHis", time() + 600);
             $data['goods_tag'] = "WXG";
             // $openid = ;//session('openid')?session('openid'):cookie('openid');
             $data['openid'] = $user['openid'];
             $this->jsApiParameters = jsapipay($data, false);
             $json['data'] = json_decode($this->jsApiParameters);
             break;
         }
         #$this->error("红包状态不能支付", U('/notes'));
         $json['error'] = 1;
         $json['message'] = "红包状态不能支付";
         break;
     } while (false);
     echo json_encode($json);
     die;
 }
Exemplo n.º 2
0
 public function zhaopian()
 {
     $json = array('error' => 0, 'message' => '', 'data' => '');
     do {
         $id = I('id', '', 'strval');
         if ($id) {
             $zhaopian = M('zhaopian')->where(array('id' => $id))->find();
             if (!$zhaopian) {
                 $json['error'] = 1;
                 $json['message'] = "找不到要购买的照片.";
                 break;
             }
             if ($zhaopian['state'] != 1) {
                 #$this->error("红包不能支付", U('/hongbao/detail', array('id'=>$hongbao['number_no'])));
                 $json['error'] = 1;
                 $json['message'] = "照片不能支付";
                 break;
             }
             if ($zhaopian['state'] != 1) {
                 #$this->error("红包已经凑齐", U('/hongbao/detail', array('id'=>$hongbao['number_no'])));
                 $json['error'] = 1;
                 $json['message'] = "照片已关闭";
                 break;
             }
             $order = M('zhaopian_order')->where(array('zhaopian_id' => $id, 'user_id' => $this->user_id, 'state' => 2))->find();
             if ($order) {
                 $json['error'] = 1;
                 $json['message'] = "您已经购买过该照片";
                 break;
             }
             if (true) {
                 $amount = ceil($order['amount'] * 100);
                 if ($amount < 1 || $amount > 20000) {
                     #$this->error("红包金额不对能支付", U('/hongbao/detail', array('id'=>$order['number_no'])));
                     $json['error'] = 1;
                     $json['message'] = "支付金额超过限制.{$amount}";
                     break;
                 }
                 $data = array();
                 $data['body'] = "xx";
                 $data['attach'] = "dd";
                 $data['order_sn'] = $order['order_sn'];
                 $data['total_fee'] = $amount;
                 $data['time_start'] = date('YmdHis');
                 $data['time_expire'] = date("YmdHis", time() + 600);
                 $data['goods_tag'] = "HBZ";
                 // $openid = ;//session('openid')?session('openid'):cookie('openid');
                 $data['openid'] = $order['openid'];
                 $str = '';
                 foreach ($data as $k => $v) {
                     $str .= "{$k}={$v},";
                 }
                 //
                 //                        $this->user = M('user')->find($zhaopian['user_id']);
                 //
                 //                        $this->title = "{$this->user['name']}凑红包";
                 //                        $this->zhaopian = $zhaopian;
                 //                        $this->order = $order;
                 //                        $this->id = $id;
                 try {
                     $jsApiParameters = jsapipay($data, false);
                 } catch (\Exception $e) {
                     $json['error'] = 1;
                     $json['message'] = "签名失败" . $e->getMessage() . $str;
                     break;
                 }
                 $json['data'] = json_decode($jsApiParameters);
                 break;
             } else {
                 //$this->error("红包状态不能支付", U('/hongbao/detail', array('id'=>$order['number_no'])));
                 $json['error'] = 1;
                 $json['message'] = "照片状态不能支付";
                 break;
             }
         }
         #$this->error("红包状态不能支付", U('/notes'));
         $json['error'] = 1;
         $json['message'] = "照片状态不能支付";
         break;
     } while (false);
     echo json_encode($json);
     die;
 }
Exemplo n.º 3
0
 public function pay1()
 {
     $json = array('error' => 0, 'message' => '', 'data' => '');
     do {
         $id = I('id', '', 'strval');
         if ($id) {
             $order = M('hongbao_order')->where(array('order_sn' => $id))->find();
             if ($order) {
                 $hongbao = M('hongbao')->where(array('number_no' => $order['number_no']))->find();
                 if ($hongbao['state'] != 1) {
                     #$this->error("红包不能支付", U('/hongbao/detail', array('id'=>$hongbao['number_no'])));
                     $json['error'] = 1;
                     $json['message'] = "红包不能支付";
                     break;
                 }
                 if ($hongbao['total_part'] <= $hongbao['total_num']) {
                     #$this->error("红包已经凑齐", U('/hongbao/detail', array('id'=>$hongbao['number_no'])));
                     $json['error'] = 1;
                     $json['message'] = "红包已经凑齐";
                     break;
                 }
                 if ($hongbao['addtime'] + 86400 < time()) {
                     #$this->error("红包已经过期", U('/hongbao/detail', array('id'=>$hongbao['number_no'])));
                     $json['error'] = 1;
                     $json['message'] = "红包已经过期~";
                     break;
                 }
                 if ($order['state'] == 1) {
                     $amount = ceil($order['total_amount'] * 100);
                     if ($amount < 1) {
                         #$this->error("红包金额不对能支付", U('/hongbao/detail', array('id'=>$order['number_no'])));
                         $json['error'] = 1;
                         $json['message'] = "红包金额不对能支付";
                         break;
                     }
                     $data['body'] = "凑红包";
                     $data['attach'] = "凑红包";
                     $data['order_sn'] = $order['order_sn'];
                     $data['total_fee'] = $amount;
                     $data['time_start'] = date('YmdHis');
                     $data['time_expire'] = date("YmdHis", time() + 600);
                     $data['goods_tag'] = "BAO";
                     // $openid = ;//session('openid')?session('openid'):cookie('openid');
                     $data['openid'] = $order['openid'];
                     $this->user = M('user')->find($hongbao['user_id']);
                     $this->title = "{$this->user['name']}凑红包";
                     $this->hongbao = $hongbao;
                     $this->order = $order;
                     $this->id = $id;
                     $this->jsApiParameters = jsapipay($data, false);
                     $json['data'] = json_decode($this->jsApiParameters);
                     break;
                 } else {
                     //$this->error("红包状态不能支付", U('/hongbao/detail', array('id'=>$order['number_no'])));
                     $json['error'] = 1;
                     $json['message'] = "红包状态不能支付";
                     break;
                 }
             }
         }
         #$this->error("红包状态不能支付", U('/notes'));
         $json['error'] = 1;
         $json['message'] = "红包状态不能支付";
         break;
     } while (false);
     echo json_encode($json);
     die;
 }
Exemplo n.º 4
0
 /**
  * 添加福利
  */
 public function add()
 {
     $json = array('msg_code' => 10001, 'msg_content' => '');
     do {
         $id = I('post.id', '', 'strval');
         $amount = I('post.amount', 0, 'floatval');
         $total = I('post.total', 0, 'intval');
         $remark = I('post.remark', '', 'htmlspecialchars');
         $remark = str_replace('红包', '福利', $remark);
         $from_bao_id = I('post.from_id', '', 'strval');
         if ($amount <= 1 || $total < 1) {
             $json['msg_code'] = 10002;
             $json['msg_content'] = '请输入福利金额或福利个数';
             break;
         }
         if ($amount / $total < 1.05 || $amount / $total > 200) {
             $json['msg_code'] = 10002;
             $json['msg_content'] = '平均每个福利范围在1.05-200之间.';
             break;
         }
         $re = '';
         if ($id) {
             $re = M('bao')->where(array('number_no' => $id))->find();
         }
         $user = M('user')->find($this->user_id);
         if (!$re || $re && $re['total_amount'] != $amount) {
             // `id`, `number_no`, `user_id`, `part_amount`, `total_amount`, `total_part`, `remark`, `addtime`, `update_time`, `state`
             $order_sn = get_order_sn('HB');
             $data['number_no'] = get_order_sn();
             $number_no = $data['number_no'];
             $data['from_user_id'] = $this->user_id;
             $data['from_openid'] = $user['openid'];
             $data['from_number_no'] = $number_no;
             if ($from_bao_id) {
                 $from_bao = M('bao')->where(array('number_no' => $from_bao_id))->find();
                 if ($from_bao) {
                     $data['from_bao_id'] = $from_bao['id'];
                     $data['from_user_id'] = $from_bao['user_id'];
                     $data['from_openid'] = $from_bao['openid'];
                     $data['from_number_no'] = $from_bao['number_no'];
                 }
             }
             $data['order_sn'] = $order_sn;
             $data['user_id'] = $this->user_id;
             $data['total_amount'] = $amount;
             $data['total_num'] = $total;
             $data['remark'] = $remark;
             $data['addtime'] = time();
             $data['state'] = 1;
             $data['openid'] = $user['openid'];
             $data['is_rand'] = 1;
             $re = M('bao')->add($data);
         } else {
             $order_sn = $re['order_sn'];
             $number_no = $re['number_no'];
         }
         if ($re) {
             $json['number_no'] = $from_bao_id ? $from_bao_id : $number_no;
             $new = array();
             // redirect(U('/hongbao/detail', array('id'=>$data['number_no'])));
             $new['body'] = "福利";
             $new['attach'] = "福利";
             $new['order_sn'] = $order_sn;
             $new['total_fee'] = $amount * 100;
             $new['time_start'] = date('YmdHis');
             $new['time_expire'] = date("YmdHis", time() + 600);
             $new['goods_tag'] = "BAO";
             // $openid = ;//session('openid')?session('openid'):cookie('openid');
             $new['openid'] = $user['openid'];
             $json['jsApiParameters'] = json_decode(jsapipay($new, false));
             break;
         } else {
             $json['msg_code'] = 10002;
             $json['msg_content'] = '福利创建失败.';
             break;
         }
     } while (false);
     echo json_encode($json);
     die;
 }
Exemplo n.º 5
0
 /**
  * 红包详情
  */
 public function detail()
 {
     $this->title = "红包照片详情";
     $id = I('get.id', 0, 'strval');
     $this->show_share = I('get.show_share', 0, 'strval');
     if ($id < 1) {
         $this->error('请选择查看的红包照片', U('/zhao/notes'));
     }
     $this->zhaopian = M('zhaopian')->where(array('number_no' => $id))->find();
     if ($this->zhaopian['state'] == 99) {
         $this->error('该红包照片已删除', U('/zhao/notes'));
     }
     if (!$this->zhaopian) {
         $this->error('没找到红包照片详情', U('/zhao/notes'));
     }
     //
     $path = C('UPLOAD_PATH') . $this->zhaopian['pic_url'];
     if (file_exists($path . "_thumb2.jpg")) {
         $this->gaosi_img = "/uploads/" . $this->zhaopian['pic_url'] . '_thumb2.jpg';
     } else {
         $this->gaosi_img = '/img/default.jpg';
     }
     $this->zhaopian_user = M('user')->find($this->zhaopian['user_id']);
     $this->user = M('user')->find($this->user_id);
     $this->title = "{$this->zhaopian_user['name']}发布的红包照片";
     $zhaopian_order = M('zhaopian_order')->where(array('zhaopian_id' => $this->zhaopian['id'], 'user_id' => $this->user_id, 'state' => 2))->find();
     $this->zhaopian_order = $zhaopian_order;
     $total_amount = M('zhaopian_order')->where(array('zhaopian_id' => $this->zhaopian['id'], 'state' => 2))->sum('amount');
     $this->total_amount = number_format(floatval($total_amount) * 0.98, 2);
     $this->total_num = M('zhaopian_order')->where(array('zhaopian_id' => $this->zhaopian['id'], 'state' => 2))->count();
     $this->is_buy = $zhaopian_order ? 1 : 0;
     $this->jsApiParameters = '1';
     //$this->is_buy=true;
     if (!$this->is_buy) {
         $img_path = ROOT_PATH . 'uploads/' . $this->zhaopian['pic_url'];
         $this->width = 750;
         $this->height = 1334;
         if (file_exists($img_path) && is_file($img_path)) {
             // 获取图片宽高
             $img = new \Think\Image(2);
             $img->open($img_path);
             $this->width = $img->width();
             $this->height = $img->height();
         }
         $order = M('zhaopian_order')->where(array('zhaopian_id' => $this->zhaopian['id'], 'user_id' => $this->user_id, 'state' => 1))->find();
         if (!$order) {
             $user = M('user')->find($this->user_id);
             if ($this->zhaopian['is_rand'] > 0) {
                 $amount = $this->getRandomAmount();
             } else {
                 $amount = $this->zhaopian['min_amount'];
             }
             $data = array('zhaopian_id' => $this->zhaopian['id'], 'zhaopian_user_id' => $this->zhaopian['user_id'], 'zhaopian_openid' => $this->zhaopian['openid'], 'number_no' => $this->zhaopian['number_no'], 'order_sn' => get_order_sn('ZP'), 'user_id' => $this->user_id, 'amount' => $amount, 'addtime' => time(), 'state' => 1, 'openid' => $user['openid']);
             $rs = M('zhaopian_order')->add($data);
             if ($rs) {
                 $order = M('zhaopian_order')->find($rs);
             }
         } else {
             if ($this->zhaopian['is_rand'] > 0) {
                 $amount = $this->getRandomAmount();
                 $order['amount'] = $amount;
                 $order['order_sn'] = get_order_sn('ZP');
                 M('zhaopian_order')->where(array('id' => $order['id']))->save(array('amount' => $amount, 'order_sn' => $order['order_sn']));
             }
         }
         if ($order['state'] == 1) {
             $data['body'] = "红包照片";
             $data['attach'] = "红包照片";
             $data['order_sn'] = $order['order_sn'];
             $data['total_fee'] = ceil(bcmul($order['amount'], 100));
             $data['time_start'] = date('YmdHis');
             $data['time_expire'] = date("YmdHis", time() + 600);
             $data['goods_tag'] = "WXG";
             // $openid = ;//session('openid')?session('openid'):cookie('openid');
             $data['openid'] = cookie('openid') ? cookie('openid') : $order['openid'];
             $jsApiParameters = jsapipay($data, false);
             // print_r($jsApiParameters);
             $this->jsApiParameters = $jsApiParameters;
         }
         $this->order = $order;
     }
     $this->pic_list = array();
     $this->img_left = ceil(20 * $this->zhaopian['total_pic'] / 2);
     if ($this->is_buy) {
         if ($this->zhaopian['total_pic'] > 1) {
             $this->pic_list = M('zhaopian_pic')->where(array('zhaopian_id' => $this->zhaopian['id']))->order('id desc')->select();
         }
     }
     if ($this->zhaopian['user_id'] == $this->user_id) {
         /*
          1,分享自己发的
         标题:我发布了3张照片,想看吗?
         内容:“用户输入的内容”
         2,分享别人发的
         李陆鸣发布了3张照片,想看吗?
         3,买了别人的照片
         我买了李陆鸣的照片,推荐!
         
         分享朋友圈
         1,分享自己发的
         标题:我发布了3张照片,想看吗?“据说看了能提升幸福感~”
         2,分享别人的
         标题:李陆鸣发布了3张照片,想看吗?“据说看了能提升幸福感~”
         3,买了别人的照片
         标题:我买了李陆鸣发布的照片,推荐!“据说看了能提升幸福感~”
         */
         $this->share_title_friend = "我发布了{$this->zhaopian['total_pic']}张照片,想看吗?“{$this->zhaopian['remark']}”";
         $this->share_title = "我发布了{$this->zhaopian['total_pic']}张照片,想看吗?";
         $this->share_link = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
         $this->share_imgUrl = "http://{$_SERVER['HTTP_HOST']}/images/silogocover.jpg";
         $this->share_desc = "“{$this->zhaopian['remark']}”";
     } else {
         if ($this->is_buy) {
             $this->share_title_friend = "我买了{$this->zhaopian_user['name']}发布的照片,推荐!“{$this->zhaopian['remark']}”";
             $this->share_title = "我买了{$this->zhaopian_user['name']}的照片,推荐!";
         } else {
             $this->share_title_friend = "{$this->zhaopian_user['name']}发布了{$this->zhaopian['total_pic']}张照片,想看吗?“{$this->zhaopian['remark']}”";
             $this->share_title = "{$this->zhaopian_user['name']}发布了{$this->zhaopian['total_pic']}张照片,想看吗?";
         }
         $this->share_link = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
         $this->share_imgUrl = "http://{$_SERVER['HTTP_HOST']}/images/silogocover.jpg";
         $this->share_desc = "“{$this->zhaopian['remark']}”";
     }
     $order_list = M('zhaopian_order')->where(array(array('number_no' => $id, 'state' => array('in', array(2)))))->order("addtime desc")->select();
     if ($order_list) {
         foreach ($order_list as $k => $order) {
             $user = M('user')->find($order['user_id']);
             $order_list[$k]['user'] = $user;
         }
     }
     $this->share_link = U('/zhao/zhaopian/detail', array('id' => $id), true, true);
     $this->order_list = $order_list;
     $this->base_url = "http://{$_SERVER['HTTP_HOST']}";
     $this->id = $id;
     $this->display();
 }