RefillPhone.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace refill\rsanfang;
  3. require_once(BASE_HELPER_RAPI_PATH . '/rsanfang/config.php');
  4. use refill;
  5. class RefillPhone extends refill\IRefillThird
  6. {
  7. public function __construct($cfgs)
  8. {
  9. parent::__construct($cfgs);
  10. }
  11. private function getProductCode($goods_id, $sys_pcode)
  12. {
  13. $thrid_refill = Model('thrid_refill');
  14. $store_id = $this->mStoreID;
  15. $product = $thrid_refill->getProviderProduct($store_id, $goods_id, $sys_pcode);
  16. if (empty($product)) {
  17. return false;
  18. } else {
  19. return $product['channel_code'];
  20. }
  21. }
  22. //启用主动查询功能
  23. public function callback() {
  24. return false;
  25. }
  26. public function add($card_no, $card_type, $amount, $params, &$net_errno = 0): array
  27. {
  28. $order_sn = $params['order_sn'];
  29. $goods_id = intval($params['goods_id']);
  30. $channel_code = $this->getProductCode($goods_id, $params['product_code']);
  31. if (empty($channel_code)) {
  32. return [false, '产品有误', false];
  33. }
  34. $mchid = $params['mchid'];
  35. $times = config::getTimes($channel_code);
  36. if($times <= 0) {
  37. return [false, '产品有误', false];
  38. }
  39. $model_merchant = Model('merchant');
  40. $data = [
  41. 'query_total_times' => ['exp', "query_total_times+$times"],
  42. 'query_left_times' => ['exp', "query_left_times+$times"]
  43. ];
  44. $ret = $model_merchant->editMerchant($data, ['mchid' => $mchid]);
  45. if($ret) {
  46. return [true, $order_sn, false];
  47. } else {
  48. return [true, '更新数据库出错', false];
  49. }
  50. }
  51. public function query($refill_info): array
  52. {
  53. $order_sn = $refill_info['order_sn'];
  54. $ch_trade_no = $refill_info['ch_trade_no'];
  55. if ($order_sn == $ch_trade_no) {
  56. return [true, ORDER_STATE_SUCCESS, ''];
  57. } else {
  58. return [true, ORDER_STATE_SEND, ''];
  59. }
  60. }
  61. public function balance(): array
  62. {
  63. return [true, 0];
  64. }
  65. }