123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <?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();
- $oil_amount = $phone_amount = [];
- foreach ($goods as $type => $amounts)
- {
- if($type == 'sinopec' || $type == 'petrochina') {
- $oil_amount = array_merge($oil_amount,$amounts);
- }
- elseif($type == 'chinamobile' || $type == 'chinaunicom' || $type == 'chinatelecom'){
- $phone_amount = array_merge($phone_amount,$amounts);
- }
- else {
- Log::record("goods err type:{$type}",Log::ERR);
- }
- }
- $oil_amount = array_unique($oil_amount);
- sort($oil_amount);
- $phone_amount = array_unique($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);
- if($card_type == mtopcard\UnknownCard) {
- return [false,'卡类型无法识别'];
- }
- // if($card_type === mtopcard\PetroChinaCard)
- // {
- // if(empty($params['idcard'])) {
- // return [false,'中石油需要参数没有包含身份证号码:idcard'];
- // }
- // if(empty($params['card_name'])) {
- // return [false,'参数没有包含身份证姓名:card_name'];
- // }
- // }
- 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_no = trim($params['cardno']);
- $card_no = explode(',' , $card_no);
- if(empty($card_no)){
- return self::outerr(errcode::ErrParamter, "卡号格式错误或未上传");
- }
- $idcard = $params['idcard'] ?? '';
- $card_name = $params['card_name'] ?? '';
- //成功个数、失败个数
- $success_no = $error_no = 0;
- $data = [];
- $all_no = count($card_no);
- foreach ($card_no as $no)
- {
- $params['cardno'] = $no;
- [$success,$error] = $this->check_params($params);
- if($success === false) {
- $error_no++;
- $arr['state'] = 201;
- $arr['err'] = $error;
- }
- else
- {
- [$state, $err] = refill\RefillFactory::instance()->add($mchid, $merchant_info['admin_id'], $amount, $no, '', $idcard, $card_name, '');
- $arr['state'] = $state;
- $arr['err'] = $err;
- if($state === true) {
- $success_no++;
- }
- else {
- $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);
- }
- }
|