checkout.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <?php
  2. namespace WY\app\controller;
  3. use WY\app\libs\Controller;
  4. use WY\app\libs\Http;
  5. use WY\app\model\Pushorder;
  6. use WY\app\model\Checkacc;
  7. if (!defined('WY_ROOT')) {
  8. exit;
  9. }
  10. class checkout extends Controller
  11. {
  12. public $paytpe = '';
  13. public $bankcode = '';
  14. public $sign = '';
  15. public $orders = '';
  16. function __construct()
  17. {
  18. parent::__construct();
  19. if ($this->config['is_checkout_state'] == 1) {
  20. $this->put('retmsg.php', array('msg' => '收银台暂时关闭,请联系客服!'));
  21. exit;
  22. }
  23. if ($this->config['is_checkout_jump'] && $this->config['checkout_jump_url'] && $this->config['checkout_jump_url'] != $this->req->server('HTTP_HOST') && isset($_REQUEST)) {
  24. $urlstr = '';
  25. foreach ($_REQUEST as $key => $val) {
  26. $urlstr .= $urlstr ? '&' : '';
  27. $urlstr .= $key . '=' . $val;
  28. }
  29. header('location:http://' . $this->config['checkout_jump_url'] . '/checkout?' . $urlstr);
  30. exit;
  31. }
  32. $this->checkacc = new Checkacc();
  33. }
  34. public function index()
  35. {
  36. $version = '1.0';
  37. $customerid = $this->req->request('customerid');
  38. $sdorderno = $this->req->request('sdorderno');
  39. $total_fee = $this->req->request('total_fee');
  40. $notifyurl = $this->req->request('notifyurl');
  41. $returnurl = $this->req->request('returnurl');
  42. $remark = $this->req->request('remark');
  43. $sign = $this->req->request('sign');
  44. if ($version == '' || $customerid == '' || $sdorderno == '' || $total_fee == '' || $notifyurl == '' || $returnurl == '' || $sign == '') {
  45. $ret['code'] = '200';
  46. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  47. $this->put('retmsg.php', $ret);
  48. exit;
  49. }
  50. if (strlen($sdorderno) > 50) {
  51. $ret['code'] = '203';
  52. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  53. $this->put('retmsg.php', $ret);
  54. exit;
  55. }
  56. // if ($total_fee > 5000) {
  57. // $ret['code'] = '207';
  58. // $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  59. // $this->put('retmsg.php', $ret);
  60. // exit;
  61. // }
  62. if ($remark && strlen($remark) > 50) {
  63. $ret['code'] = '204';
  64. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  65. $this->put('retmsg.php', $ret);
  66. exit;
  67. }
  68. $userData = $this->model()->select()->from('users')->where(array('fields' => 'id=?', 'values' => array($customerid)))->fetchRow();
  69. if (!$userData) {
  70. $ret['code'] = '001';
  71. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  72. $this->put('retmsg.php', $ret);
  73. exit;
  74. }
  75. if ($userData['is_state'] == '0') {
  76. $ret['code'] = '002';
  77. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  78. $this->put('retmsg.php', $ret);
  79. exit;
  80. }
  81. if ($userData['is_state'] == '2') {
  82. $ret['code'] = '003';
  83. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  84. $this->put('retmsg.php', $ret);
  85. exit;
  86. }
  87. if (!$userData['is_checkout']) {
  88. $ret['code'] = '105';
  89. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  90. $this->put('retmsg.php', $ret);
  91. exit;
  92. }
  93. if ($userData['is_verify_siteurl']) {
  94. $userInfo = $this->model()->select('siteurl')->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($customerid)))->fetchRow();
  95. if ($userInfo) {
  96. $fromUrl = $this->req->server('HTTP_REFERER');
  97. if (strpos($fromUrl, $userInfo['siteurl']) === false) {
  98. $ret['code'] = '206';
  99. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  100. $this->put('retmsg.php', $ret);
  101. exit;
  102. }
  103. }
  104. }
  105. $total_fee = number_format($total_fee, 2, '.', '');
  106. $signStr = 'version=' . $version . '&customerid=' . $customerid . '&total_fee=' . $total_fee . '&sdorderno=' . $sdorderno . '&notifyurl=' . $notifyurl . '&returnurl=' . $returnurl . '&' . $userData['apikey'];
  107. $mysign = md5($signStr);
  108. if ($sign != $mysign) {
  109. $ret['code'] = '201';
  110. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  111. $this->put('retmsg.php', $ret);
  112. exit;
  113. }
  114. if ($this->model()->select()->from('orders')->where(array('fields' => 'userid=? and sdorderno=?', 'values' => array($customerid, $sdorderno)))->count()) {
  115. $ret['code'] = '205';
  116. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  117. $this->put('retmsg.php', $ret);
  118. exit;
  119. }
  120. $orderid = $this->res->getOrderID();
  121. $token = sha1($this->res->getRandomString(40));
  122. $addtime = time();
  123. $orderinfo = array('userid' => $customerid, 'notifyurl' => $notifyurl, 'returnurl' => $returnurl, 'remark' => $remark, 'addtime' => $addtime);
  124. if (!($orderinfoid = $this->model()->from('orderinfo')->insertData($orderinfo)->insert())) {
  125. $ret['code'] = '209';
  126. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  127. $this->put('retmsg.php', $ret);
  128. exit;
  129. }
  130. $orderdata = array('userid' => $customerid, 'agentid' => $userData['superid'], 'orderid' => $orderid, 'sdorderno' => $sdorderno, 'total_fee' => $total_fee, 'addtime' => $addtime, 'lastime' => $addtime, 'is_paytype' => 1, 'orderinfoid' => $orderinfoid);
  131. if (!($orid = $this->model()->from('orders')->insertData($orderdata)->insert())) {
  132. $ret['code'] = '210';
  133. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  134. $this->put('retmsg.php', $ret);
  135. exit;
  136. }
  137. $ordernotify = array('orid' => $orid, 'addtime' => $addtime);
  138. if (!$this->model()->from('ordernotify')->insertData($ordernotify)->insert()) {
  139. $ret['code'] = '211';
  140. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  141. $this->put('retmsg.php', $ret);
  142. exit;
  143. }
  144. if (!$this->model()->from('checkout')->insertData(array('orid' => $orid, 'token' => $token))->insert()) {
  145. $ret['code'] = '212';
  146. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  147. $this->put('retmsg.php', $ret);
  148. exit;
  149. }
  150. $this->res->redirect('/checkout/pay?sign=' . $token);
  151. }
  152. public function pay()
  153. {
  154. $sign = $this->req->get('sign');
  155. if ($sign == '' || !($checkout = $this->model()->select()->from('checkout')->where(array('fields' => 'token=?', 'values' => array($sign)))->fetchRow())) {
  156. $ret['code'] = '213';
  157. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  158. $this->put('retmsg.php', $ret);
  159. exit;
  160. }
  161. if (!($orders = $this->model()->select()->from('orders')->where(array('fields' => 'id=?', 'values' => array($checkout['orid'])))->fetchRow())) {
  162. $ret['code'] = '214';
  163. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  164. $this->put('retmsg.php', $ret);
  165. exit;
  166. }
  167. if ($orders['is_state'] == '1') {
  168. $ret['code'] = '215';
  169. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  170. $this->put('retmsg.php', $ret);
  171. exit;
  172. }
  173. if ($orders['is_state'] == '3') {
  174. $ret['code'] = '216';
  175. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  176. $this->put('retmsg.php', $ret);
  177. exit;
  178. }
  179. if ($orders['is_state'] == '0' && time() - $orders['addtime'] >= 60 * 30) {
  180. $this->model()->from('orders')->updateSet(array('is_state' => 3))->where(array('fields' => 'id=?', 'values' => array($checkout['orid'])))->update();
  181. $ret['code'] = '217';
  182. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  183. $this->put('retmsg.php', $ret);
  184. exit;
  185. }
  186. $orderinfo = $this->model()->select()->from('orderinfo')->where(array('fields' => 'id=?', 'values' => array($orders['orderinfoid'])))->fetchRow();
  187. $userinfo = $this->model()->select()->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($orders['userid'])))->fetchRow();
  188. $banklist = $this->model()->select()->from('acb')->where(array('fields' => 'is_state=?', 'values' => array(0)))->fetchAll();
  189. $cardlist = array();
  190. $acc = $this->model()->select('acwid,id,gateway')->from('acc')->where(array('fields' => 'is_state=? and is_card=?', 'values' => array(0, 1)))->fetchAll();
  191. if ($acc) {
  192. $userprice = $this->model()->select('channelid')->from('userprice')->where(array('fields' => 'userid=? and is_state=?', 'values' => array($orders['userid'], 0)))->fetchAll();
  193. foreach ($acc as $key => $val) {
  194. foreach ($userprice as $key2 => $val2) {
  195. if ($val['id'] == $val2['channelid']) {
  196. $cardlist[] = array('acwid' => $val['acwid'], 'gateway' => $val['gateway']);
  197. }
  198. }
  199. }
  200. $acw = $this->model()->select()->from('acw')->where(array('fields' => 'price<>?', 'values' => array('')))->fetchAll();
  201. if ($cardlist && $acw) {
  202. foreach ($cardlist as $key => $val) {
  203. foreach ($acw as $key2 => $val2) {
  204. if ($val['acwid'] == $val2['id']) {
  205. $cardlist[$key]['img'] = $val2['img'];
  206. }
  207. }
  208. }
  209. }
  210. }
  211. $data = array('title' => '收银台', 'userinfo' => $userinfo, 'banklist' => $banklist, 'cardlist' => $cardlist, 'orders' => $orders, 'orderinfo' => $orderinfo, 'token' => $sign);
  212. if ($this->res->isMobile()) {
  213. $this->put('checkoutwap.php', $data);
  214. exit;
  215. }
  216. $this->put('checkout.php', $data);
  217. }
  218. public function is_weixin() {
  219. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
  220. return true;
  221. } return false;
  222. }
  223. public function subpay()
  224. {
  225. $sign = $this->req->get('sign');
  226. $paytype = $this->req->post('paytype');
  227. $bankcode = $this->req->post('bankcode');
  228. $bankcode = $paytype == 'bank' || $paytype == 'card' ? $bankcode : $paytype;
  229. if ($sign == '' || $paytype == '' || $bankcode == '') {
  230. $ret['code'] = '208';
  231. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  232. $this->put('retmsg.php', $ret);
  233. exit;
  234. }
  235. if (!($checkout = $this->model()->select()->from('checkout')->where(array('fields' => 'token=?', 'values' => array($sign)))->fetchRow())) {
  236. $ret['code'] = '213';
  237. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  238. $this->put('retmsg.php', $ret);
  239. exit;
  240. }
  241. if (!($orders = $this->model()->select()->from('orders')->where(array('fields' => 'id=?', 'values' => array($checkout['orid'])))->fetchRow())) {
  242. $ret['code'] = '214';
  243. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  244. $this->put('retmsg.php', $ret);
  245. exit;
  246. }
  247. if ($orders['is_state'] == '1') {
  248. $ret['code'] = '215';
  249. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  250. $this->put('retmsg.php', $ret);
  251. exit;
  252. }
  253. if ($orders['is_state'] == '3') {
  254. $ret['code'] = '216';
  255. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  256. $this->put('retmsg.php', $ret);
  257. exit;
  258. }
  259. if ($orders['is_state'] == '0' && time() - $orders['addtime'] >= 60 * 30) {
  260. $this->model()->from('orders')->updateSet(array('is_state' => 3))->where(array('fields' => 'id=?', 'values' => array($checkout['orid'])))->update();
  261. $ret['code'] = '217';
  262. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  263. $this->put('retmsg.php', $ret);
  264. exit;
  265. }
  266. $this->orders = $orders;
  267. $this->paytype = $paytype;
  268. $this->bankcode = $bankcode;
  269. $this->sign = $sign;
  270. if ($paytype == 'card') {
  271. $this->card();
  272. } else {
  273. $this->uncard();
  274. }
  275. }
  276. public function card()
  277. {
  278. $acc = $this->model()->select()->from('acc')->where(array('fields' => 'gateway=?', 'values' => array($this->bankcode)))->fetchRow();
  279. if (!$acc) {
  280. $ret['code'] = '103';
  281. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  282. $this->put('retmsg.php', $ret);
  283. exit;
  284. }
  285. if ($acc['is_state'] == '1') {
  286. $ret['code'] = '102';
  287. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  288. $this->put('retmsg.php', $ret);
  289. exit;
  290. }
  291. $userprice = $this->model()->select()->from('userprice')->where(array('fields' => 'channelid=? and userid=?', 'values' => array($acc['id'], $this->orders['userid'])))->fetchRow();
  292. if (!$userprice) {
  293. $ret['code'] = '101';
  294. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  295. $this->put('retmsg.php', $ret);
  296. exit;
  297. }
  298. if ($userprice['is_state'] == '1') {
  299. $ret['code'] = '100';
  300. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  301. $this->put('retmsg.php', $ret);
  302. exit;
  303. }
  304. $this->model()->from('orders')->updateSet(array('channelid' => $acc['id']))->where(array('fields' => 'id=?', 'values' => array($this->orders['id'])))->update();
  305. $userinfo = $this->model()->select()->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($this->orders['userid'])))->fetchRow();
  306. $orderinfo = $this->model()->select()->from('orderinfo')->where(array('fields' => 'id=?', 'values' => array($this->orders['orderinfoid'])))->fetchRow();
  307. $acw = $this->model()->select()->from('acw')->where(array('fields' => 'id=?', 'values' => array($acc['acwid'])))->fetchRow();
  308. $data = array('title' => '收银台', 'userinfo' => $userinfo, 'orderinfo' => $orderinfo, 'cardvalue' => json_decode($acw['price']), 'cardname' => $acw['name'], 'cardlength' => json_decode($acw['length']), 'orders' => $this->orders, 'token' => $this->sign, 'acc' => $acc);
  309. $this->put('cards.php', $data);
  310. exit;
  311. }
  312. private function uncard()
  313. {
  314. $acw = $this->model()->select()->from('acw')->where(array('fields' => 'code=?', 'values' => array($this->paytype)))->fetchRow();
  315. if (!$acw) {
  316. $ret['code'] = '500';
  317. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  318. $this->put('retmsg.php', $ret);
  319. exit;
  320. }
  321. /*$acc=$this->model()->select()->from('acc')->where(array('fields'=>'acwid=?','values'=>array($acw['id'])))->fetchAll();if(!$acc){$ret['code']='103';$ret['msg']=$this->setConfig->retMsg($ret['code']);$this->put('retmsg.php',$ret);exit;}$userprice=$this->model()->select()->from('userprice')->where(array('fields'=>'userid=?','values'=>array($this->orders['userid'])))->fetchAll();if(!$userprice){$ret['code']='101';$ret['msg']=$this->setConfig->retMsg($ret['code']);$this->put('retmsg.php',$ret);exit;}$is_state=$channelid=$acpcode=$gateway=$is_state_acc='';foreach($userprice as $key=>$val){foreach($acc as $key2=>$val2){if($val['channelid']==$val2['id']){$is_state=$val['is_state'];$channelid=$val['channelid'];$acpcode=$val2['acpcode'];$gateway=$val2['gateway'];$is_state_acc=$val2['is_state'];break;}}}if($acpcode=='' || $gateway==''){$ret['code']='103';$ret['msg']=$this->setConfig->retMsg($ret['code']);$this->put('retmsg.php',$ret);exit;}if($is_state=='1'){$ret['code']='100';$ret['msg']=$this->setConfig->retMsg($ret['code']);$this->put('retmsg.php',$ret);exit;}if($is_state_acc=='1'){$ret['code']='102';$ret['msg']=$this->setConfig->retMsg($ret['code']);$this->put('retmsg.php',$ret);exit;}*/
  322. $acc = $this->model()->select('a.id,a.acpcode,a.gateway,a.is_state,b.is_state as is_state_acc,b.channelid')->from('acc a')->left('userprice b')->on('b.channelid=a.id')->join()->where(array('fields' => 'b.userid=? and a.acwid=?', 'values' => array($this->orders['userid'], $acw['id'])))->fetchRow();
  323. if (!$acc) {
  324. $ret['code'] = '103';
  325. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  326. $this->put('retmsg.php', $ret);
  327. exit;
  328. }
  329. if ($acc['is_state'] == '1') {
  330. $ret['code'] = '100';
  331. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  332. $this->put('retmsg.php', $ret);
  333. exit;
  334. }
  335. if ($acc['is_state_acc'] == '1') {
  336. $ret['code'] = '102';
  337. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  338. $this->put('retmsg.php', $ret);
  339. exit;
  340. }
  341. $channelid = $acc['channelid'];
  342. $acpcode = $acc['acpcode'];
  343. $gateway = $acc['gateway'];
  344. $data = array('channelid' => $acc['id']);
  345. $this->model()->from('orders')->updateSet($data)->where(array('fields' => 'id=?', 'values' => array($this->orders['id'])))->update();
  346. $data = array('paytype' => $this->paytype, 'bankcode' => $this->bankcode, 'faceno' => '', 'cardnum' => '', 'cardpwd' => '');
  347. $this->model()->from('orderinfo')->updateSet($data)->where(array('fields' => 'id=?', 'values' => array($this->orders['orderinfoid'])))->update();
  348. $orderinfo = $this->model()->select()->from('orderinfo')->where(array('fields' => 'id=?', 'values' => array($this->orders['orderinfoid'])))->fetchRow();
  349. $url = 'http://' . $this->req->server('HTTP_HOST') . '/pay/' . $acpcode . '_' . $gateway . '/send.php';
  350. $url .= '?orderid=' . $this->orders['orderid'] . '&price=' . $this->orders['total_fee'] . '&bankcode=' . $this->bankcode . '&remark=' . $orderinfo['remark'];
  351. $this->res->redirect($url);
  352. }
  353. public function cardpay()
  354. {
  355. $sign = $this->req->post('sign');
  356. $cardvalue = $this->req->post('cardvalue');
  357. $cardnum = $this->req->post('cardnum');
  358. $cardpwd = $this->req->post('cardpwd');
  359. $accid = $this->req->post('accid');
  360. if ($sign == '' || $cardvalue == '' || $cardnum == '' || $cardpwd == '' || $accid == '') {
  361. echo json_encode(array('status' => 0, 'msg' => '选项填写不完整'));
  362. exit;
  363. }
  364. if (!($checkout = $this->model()->select()->from('checkout')->where(array('fields' => 'token=?', 'values' => array($sign)))->fetchRow())) {
  365. echo json_encode(array('status' => 0, 'msg' => '订单不存在'));
  366. exit;
  367. }
  368. if (!($orders = $this->model()->select()->from('orders')->where(array('fields' => 'id=?', 'values' => array($checkout['orid'])))->fetchRow())) {
  369. echo json_encode(array('status' => 0, 'msg' => '订单不存在'));
  370. exit;
  371. }
  372. if ($cardvalue * 100 < $orders['total_fee'] * 100) {
  373. echo json_encode(array('status' => 0, 'msg' => '卡面值金额不能小于订单金额'));
  374. exit;
  375. }
  376. if (!($acc = $this->model()->select()->from('acc')->where(array('fields' => 'id=? and is_state=?', 'values' => array($accid, 0)))->fetchRow())) {
  377. echo json_encode(array('status' => 0, 'msg' => '点卡通道不存在'));
  378. exit;
  379. }
  380. $acw = $this->model()->select()->from('acw')->where(array('fields' => 'id=?', 'values' => array($acc['acwid'])))->fetchRow();
  381. if ($acw['length']) {
  382. $cardLength = json_decode($acw['length'], true);
  383. if (strlen($cardnum) != $cardLength[0]) {
  384. echo json_encode(array('status' => 0, 'msg' => '充值卡号长度应为' . $cardLength[0] . '位'));
  385. exit;
  386. }
  387. if (strlen($cardpwd) != $cardLength[1]) {
  388. echo json_encode(array('status' => 0, 'msg' => '充值卡密长度应为' . $cardLength[1] . '位'));
  389. exit;
  390. }
  391. }
  392. $data = array('channelid' => $acc['id']);
  393. $this->model()->from('orders')->updateSet($data)->where(array('fields' => 'id=?', 'values' => array($orders['id'])))->update();
  394. $data = array('paytype' => $acc['acpcode'], 'bankcode' => $acc['gateway'], 'cardnum' => $cardnum, 'cardpwd' => $cardpwd, 'faceno' => $cardvalue);
  395. $this->model()->from('orderinfo')->updateSet($data)->where(array('fields' => 'id=?', 'values' => array($orders['orderinfoid'])))->update();
  396. $url = 'http://' . $this->req->server('HTTP_HOST') . '/pay/' . $acc['acpcode'] . '_card/';
  397. $submitUrl = $url . 'send.php';
  398. $returnUrl = $url . 'returnUrl.php';
  399. $params = array('orderid' => $orders['orderid'], 'price' => $orders['total_fee'], 'cardnum' => $cardnum, 'cardpwd' => $cardpwd, 'cardvalue' => $cardvalue, 'gateway' => $acc['gateway']);
  400. $http = new Http($submitUrl, $params);
  401. $http->toUrl();
  402. $content = $http->getResContent();
  403. $code = $http->getResCode();
  404. $errinfo = $http->getErrInfo();
  405. $data = array('code' => $code, 'content' => $this->res->subString($content, 0, 50), 'info' => $errinfo);
  406. $this->model()->from('orderinfo')->updateSet(array('retmsg' => json_encode($data)))->where(array('fields' => 'id=?', 'values' => array($orders['orderinfoid'])))->update();
  407. if ($content == 'ok') {
  408. echo json_encode(array('status' => 1, 'msg' => '充值卡已提交成功,请稍候查看支付结果', 'url' => $returnUrl . '?orderid=' . $orders['orderid']));
  409. exit;
  410. }
  411. echo json_encode(array('status' => 0, 'msg' => '' . $content));
  412. }
  413. public function payresult()
  414. {
  415. $sign = $this->req->get('sign');
  416. if ($sign == '' || !($checkout = $this->model()->select()->from('checkout')->where(array('fields' => 'token=?', 'values' => array($sign)))->fetchRow())) {
  417. $ret['code'] = '213';
  418. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  419. $this->put('retmsg.php', $ret);
  420. exit;
  421. }
  422. if (!($orders = $this->model()->select()->from('orders')->where(array('fields' => 'id=?', 'values' => array($checkout['orid'])))->fetchRow())) {
  423. $ret['code'] = '214';
  424. $ret['msg'] = $this->setConfig->retMsg($ret['code']);
  425. $this->put('retmsg.php', $ret);
  426. exit;
  427. }
  428. $push = new Pushorder($orders['orderid']);
  429. $push->sync();
  430. }
  431. }