getPayInfo($id, $sku, $num, $user); if (!$goods) { Dever::alert('错误的商品信息'); } # 验证库存 if ($goods['num'] < $num) { Dever::alert('已售空'); } $shop = Dever::db('goods/shop')->one($goods['shop_id']); if (!$shop) { Dever::alert('店铺不存在'); } if (!$parent_uid && Dever::project('invite')) { $parent = Dever::load('invite/api')->getParent($uid, 1); if ($parent) { $parent_uid = $parent['uid']; } } if ($parent_uid) { $order_data['parent_uid'] = $parent_uid; } $order_data['type'] = $type; $order_data['type_id'] = $type_id; $order_data['name'] = $goods['name']; $order_data['uid'] = $uid; $order_data['status'] = 1; $order_data['info_id'] = $goods['id']; $order_data['sku_id'] = $sku; $order_data['mode'] = $mode; $order_data['platform'] = $goods['platform']; $order_data['shape'] = $goods['shape']; $order_data['area_id'] = $user['area_id']; $order_data['address'] = $user['address']; $order_data['username'] = $user['address_contact']; $order_data['mobile'] = $user['address_mobile']; $order_data['store_id'] = $store_id; $order_data['cash'] = $goods['price']; $order_data['freight_id'] = $goods['freight_id']; $order_data['freight_price'] = $goods['freight_price']; $order_data['num'] = $num; $price = $order_data['cash'] * $order_data['num']; if ($mode == 1) { $price += $order_data['freight_price']; } $order_data['price'] = $price; $order_data['reward'] = isset($goods['reward']) && $goods['reward'] ? $goods['reward'] : 0; $order_data['system_source'] = $system_source; $order_data['order_id'] = $this->getOrderId(); $id = Dever::db('goods/order')->insert($order_data); if (!$id) { Dever::alert('支付失败'); } $param = array ( 'project_id' => 1, 'channel_id' => $shop['pay_channel'], 'system_source' => $system_source, 'uid' => $uid, 'name' => $order_data['name'], 'cash' => $price, 'product_id' => $goods['id'], 'order_id' => $order_data['order_id'], 'refer' => $refer, ); $receipt = Dever::input('receipt'); if ($receipt) { $param['receipt'] = $receipt; } $result = Dever::load('pay/api.pay', $param); return $result; } # 支付成功回调 安全加密 设置token public function success_secure_api_token() { $project_id = Dever::input('pay_project_id'); $info = Dever::db('pay/project')->one($project_id); if ($info) { return $info['key']; } return 'goods_dever_2020'; } # 支付成功回调 安全加密 public function success_secure_api($param = array()) { $this->success($param); } # 支付成功回调 public function success($param = array()) { $send = $param ? $param : Dever::preInput('pay_'); $order_id = $send['pay_order_id']; $status = $send['pay_status']; $msg = $send['pay_msg']; $order = Dever::db('goods/order')->one(array('order_id' => $order_id, 'time' => time())); if ($order && $order['pay_status'] == 1) { if ($status == 2) { # 减少库存 增加销量 $update['where_id'] = $order['info_id']; $update['sell_num'] = $order['num']; Dever::db('goods/info')->updateSell($update); if ($order['sku_id'] > 0) { $update['where_id'] = $order['sku_id']; $update['sell_num'] = $order['num']; Dever::db('goods/info_sku')->updateSell($update); } # 增加积分 if ($order['parent_uid'] > 0 && $order['parent_uid'] != $order['uid']) { $uid = $order['parent_uid'] . '_' . $order['uid']; # 给上级发佣金 Dever::score($order['parent_uid'], 'sell_my_goods', '销售自营商品', false, $order['reward'], false, $order['type'], $order['type_id']); } else { $uid = $order['uid']; } # 榜单更新 if (Dever::project('collection')) { Dever::load('collection/lib/ranking')->up($order['uid'], $order['type_id'], 2, $order['num']); } # 给自己发佣金 Dever::score($uid, 'buy_my_goods', '购买自营商品', false, $order['reward'], false, $order['type'], $order['type_id']); # 发消息 if (Dever::project('message')) { Dever::load('message/lib/data')->push(-1, $order['uid'], '购买提醒', '购买成功', 1); } } $update['pay_status'] = $status; $update['status'] = 2; $update['where_id'] = $order['id']; $update['pay_time'] = time(); Dever::db('goods/order')->update($update); } return 'ok'; } # 生成订单号 public function getOrderId() { $where['order_id'] = Dever::order('G'); $state = Dever::db('goods/order')->one($where); if (!$state) { return $where['order_id']; } else { return $this->getOrderId(); } } }