Handleorder.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace WY\app\model;
  3. use WY\app\libs\Model;
  4. use WY\app\model\Pushorder;
  5. if (!defined('WY_ROOT')) {
  6. exit;
  7. }
  8. class Handleorder extends Model
  9. {
  10. public function __construct($orderid, $money, $cardnum = '', $cardvalue = '', $cardstate = '')
  11. {
  12. parent::__construct();
  13. $this->orderid = $orderid;
  14. $this->money = number_format($money, 2, '.', '');
  15. $this->cardnum = $cardnum;
  16. $this->cardvalue = $cardvalue;
  17. $this->cardstate = $cardstate;
  18. if ($this->money <= 0) {
  19. return false;
  20. }
  21. }
  22. public function updateUncard()
  23. {
  24. $orders = $this->getOrder();
  25. if (!$orders || $orders['is_state'] > 0) {
  26. return false;
  27. }
  28. $rate = $this->getPrice($orders['userid'], $orders['channelid']);
  29. $data = array('realmoney' => $this->money, 'uprice' => $rate['uprice'], 'gprice' => $rate['gprice'], 'wprice' => $rate['wprice'], 'is_state' => 1, 'lastime' => time());
  30. $this->model()->from('orders')->updateSet($data)->where(array('fields' => 'orderid=?', 'values' => array($this->orderid)))->update();
  31. $push = new Pushorder($this->orderid);
  32. $push->notify();
  33. }
  34. public function updateCard()
  35. {
  36. $orders = $this->getOrder();
  37. if (!$orders || $orders['is_state'] > 0) {
  38. return false;
  39. }
  40. $rate = $this->getPrice($orders['userid'], $orders['channelid']);
  41. $data = array('realmoney' => $this->money, 'uprice' => $rate['uprice'], 'gprice' => $rate['gprice'], 'wprice' => $rate['wprice'], 'is_state' => 1, 'lastime' => time());
  42. $this->model()->from('orders')->updateSet($data)->where(array('fields' => 'orderid=?', 'values' => array($this->orderid)))->update();
  43. $push = new Pushorder($this->orderid);
  44. $push->notify();
  45. }
  46. private function getPrice($userid, $channelid)
  47. {
  48. $uprice = $gprice = $wprice = 0;
  49. if ($users = $this->model()->select('superid')->from('users')->where(array('fields' => 'id=?', 'values' => array($userid)))->fetchRow()) {
  50. if ($rate = $this->model()->select('gprice')->from('userprice')->where(array('fields' => 'userid=? and channelid=?', 'values' => array($users['superid'], $channelid)))->fetchRow()) {
  51. $gprice = $rate['gprice'];
  52. }
  53. }
  54. if ($rate = $this->model()->select('uprice')->from('userprice')->where(array('fields' => 'userid=? and channelid=?', 'values' => array($userid, $channelid)))->fetchRow()) {
  55. $uprice = $rate['uprice'];
  56. }
  57. if ($rate = $this->model()->select('wprice')->from('acc')->where(array('fields' => 'id=?', 'values' => array($channelid)))->fetchRow()) {
  58. $wprice = $rate['wprice'];
  59. }
  60. return array('uprice' => $uprice, 'gprice' => $gprice, 'wprice' => $wprice);
  61. }
  62. private function getOrder()
  63. {
  64. return $this->model()->select()->from('orders')->where(array('fields' => 'orderid=?', 'values' => array($this->orderid)))->fetchRow();
  65. }
  66. }