Example #1
0
 /**
  * jsapi支付
  * @param string  $user_id    用户id
  * @param int     $order_id
  * @param string  $order_sn   订单号
  * @param int     $total_fee  费用
  * @param string  $body       商品或支付单简要描述
  * @param string  $goods_tag  商品标记
  * @param string  $attach     自定义数据
  * @return array
  */
 public function JsApiPay($user_id, $order_id, $order_sn, $total_fee, $body = '', $goods_tag = '', $attach = '')
 {
     if (empty($user_id) || empty($total_fee)) {
         return ['status' => -1, 'message' => '数据错误'];
     }
     $tools = new JsApiPay();
     $openId = UserModel::instance()->getOpenId($user_id);
     if (empty($openId)) {
         $openId = $tools->GetOpenid();
         //             return ['status'=> -2 , 'message'=>'user_id错误'];
     }
     $input = new \WxPayUnifiedOrder();
     $input->SetBody($body);
     $input->SetAttach($attach);
     $input->SetOut_trade_no($order_sn);
     //\WxPayConfig::MCHID.date("YmdHis")
     $input->SetTotal_fee($total_fee);
     $input->SetTime_start(date("YmdHis"));
     $input->SetTime_expire(date("YmdHis", time() + 600));
     $input->SetGoods_tag($goods_tag);
     $input->SetTrade_type("JSAPI");
     $input->SetOpenid($openId);
     $order = \WxPayApi::unifiedOrder($input);
     if ($order['return_code'] != 'SUCCESS') {
         return ['status' => -10, 'message' => $order['return_msg']];
     }
     $jsApiParameters = $tools->GetJsApiParameters($order);
     $this->addPayLog($openId, $order_id, $input);
     return ['status' => 1, 'message' => $jsApiParameters];
 }
Example #2
0
 /**
  * 订单列表
  */
 public function order_list()
 {
     $wx = new JsApiPay();
     $openid = $wx->GetOpenid();
     if (!empty($openid)) {
         $wx_user = OrderModel::instance()->getWxId($openid);
     } else {
         E('获取openid失败');
     }
     $wx_user_id = intval($wx_user['id']);
     //$wx_user_id = intval(I('get.mid'));
     $data = OrderModel::instance()->getOrderList($wx_user_id);
     /*$order_list = [];
     		if(is_array($data)) {
     			foreach($data as $list) {
     				$order_list[$list['shop_id']]['header'] = ['shop_name' => $list['shop_name'], 'order_status' => $list['order_status']];
     				$order_list[$list['shop_id']][] = $list;
     			}
     		}*/
     $this->assign('data', $data);
     $this->display();
 }