123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?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()
- {
- $oil_amount = [50, 100, 200, 500, 1000, 2000];
- $phone_amount = [10, 20, 30, 50, 100, 200, 300, 500];
- $phone_small_amount = [1, 2, 3, 4, 5, 6, 7, 8, 9];
- $phone_amount = array_merge($phone_amount, $phone_small_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, "用户不存在.");
- }
- if($merchant_info['manual_recharge'] != 1) {
- return self::outerr(errcode::ErrParamter, "手动充值业务已被关闭,请联系管理员。");
- }
- $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,
- 'order_time' => time(),
- '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);
- }
- private function check_pcode($pcode)
- {
- $mod_third = Model('thrid_refill');
- $product = $mod_third->getProduct(['system_code' => $pcode]);
- return !empty($product);
- }
- public function add_thirdOp()
- {
- $params = $_POST;
- $product_code = $params['product_code'];
- if($this->check_pcode($product_code) == false) {
- return self::outerr(errcode::ErrParamter, "对应的产品编码{$product_code}不存在");
- }
- $card_no = $params['card_no'];
- $mchid = $this->mchid();
- $model_merchant = Model('merchant');
- $merchant_info = $model_merchant->getMerchantInfo(['mchid' => $mchid]);
- if (empty($merchant_info)) {
- return self::outerr(errcode::ErrMemberNotExist, "用户不存在.");
- }
- if($merchant_info['manual_recharge'] != 1) {
- return self::outerr(errcode::ErrParamter, "手动充值业务已被关闭,请联系管理员。");
- }
- $mch_order = $this->make_sn();
- $input = [
- 'mchid' => $mchid,
- 'buyer_id' => intval($merchant_info['admin_id']),
- 'amount' => refill\util::ThirdRefillAmount,
- 'mch_order' => $mch_order,
- 'order_time' => time(),
- 'notify_url' => "",
- 'org_quality' => 1,
- 'card_type' => mtopcard\ThirdRefillCard,
- 'card_no' => $card_no,
- 'product_code' => $product_code,
- 'quantity' => 1,
- 'third_card_type' => 1,
- 'third_product_type' => mtopcard\ThirdOnlineProduct,
- ];
- $state = refill\util::push_addthird($input);
- if ($state) {
- return self::outsuccess([]);
- } else {
- return self::outerr(errcode::ErrOperation, "系统错误.");
- }
- }
- }
|