123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- require_once(BASE_ROOT_PATH . '/mobile/control/merchantweb.php');
- require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
- require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
- class merchant_refillControl extends mbMerchantControl
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function goodsOp()
- {
- $goods = refill\RefillFactory::instance()->goods();
- $result['oil_amount'] = [];
- $result['phone_amount'] = [];
- foreach ($goods as $type => $specs)
- {
- if($type == mtopcard\SinopecCard || $type == mtopcard\PetroChinaCard) {
- foreach ($specs as $spec) {
- $result['oil_amount'][] = $spec;
- }
- }
- else {
- foreach ($specs as $spec) {
- $result['phone_amount'][] = $spec;
- }
- }
- }
- $oil_amount = array_unique($result['oil_amount']);
- sort($oil_amount);
- $phone_amount = array_unique($result['phone_amount']);
- sort($phone_amount);
- return self::outsuccess(['oil_amount' => $oil_amount,'phone_amount' => $phone_amount]);
- }
- private function check_params($params)
- {
- if(empty($params['cardno'])) {
- return [false,'参数没有包含cardno'];
- }
- if(empty($params['amount'])) {
- return [false,'参数没有包含充值金额:amount'];
- }
- $card_no = $params['cardno'];
- $card_type = mtopcard\card_type($card_no,$regin_no);
- if($card_type == mtopcard\UnknownCard) {
- return [false,'卡类型无法识别'];
- }
- return [true,""];
- }
- public function addOp()
- {
- $params = $_POST;
- $mchid = $this->mchid();
- $model_merchant = Model('merchant');
- $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
- if (empty($merchant_info)) {
- return self::outerr(errcode::ErrMemberNotExist, "用户不存在.");
- }
- $amount = intval($params['amount']);
- $card_nos = trim($params['cardno']);
- $card_nos = explode(',' , $card_nos);
- if(empty($card_nos)){
- return self::outerr(errcode::ErrParamter, "卡号格式错误或未上传");
- }
- $quality = $params['quality'] ?? 0;
- //成功个数、失败个数
- $success_no = $error_no = 0;
- $data = [];
- $all_no = count($card_nos);
- foreach ($card_nos as $no)
- {
- $params['cardno'] = $no;
- [$success,$error] = $this->check_params($params);
- if($success === false) {
- $error_no++;
- $arr['state'] = 201;
- $arr['err'] = $error;
- }
- else
- {
- Log::record("no = {$no}",Log::DEBUG);
- $mch_order = $this->make_sn();
- $params = [ 'mchid' => $this->mchid(),
- 'buyer_id' => intval($merchant_info['admin_id']),
- 'amount' => $amount,
- 'card_no' => $no,
- 'mch_order' => $mch_order,
- 'notify_url' => "",
- 'org_quality' => $quality];
- $card_type = mtopcard\simple_card_type($no);
- [$can_refill, $period] = refill\util::can_commit($no, $card_type);
- if ($can_refill === false) {
- $ret = refill\util::async_add($params, $period);
- } else {
- $ret = refill\util::push_add($params);
- }
- if($ret) {
- $arr['state'] = $ret;
- $arr['err'] = '';
- $success_no++;
- }
- else {
- $arr['state'] = 202;
- $arr['err'] = '提交失败';
- $error_no++;
- }
- }
- $arr['card_no'] = $no;
- $arr['amount'] = $amount;
- $data[] = $arr;
- }
- $result['success_no'] = $success_no;
- $result['error_no'] = $error_no;
- $result['all_no'] = $all_no;
- $result['data'] = $data;
- return self::outsuccess($result);
- }
- private function make_sn()
- {
- return mt_rand(1000, 9999)
- . sprintf('%010d', time())
- . sprintf('%06d', (float)microtime() * 1000000);
- }
- }
|