check($node)) { throw new Exception(''); } $this->product_amount = intval($node['product_amount'] ?? 0); $this->product_name = $node['product_name']; $this->plat_code = $node['plat_code']; $this->mch_id = intval($node['mch_id']); $this->mch_price = ncPriceFormat($node['mch_price']); $this->store_code = $node['store_code']; $this->store_id = intval($node['store_id']); $this->store_price = ncPriceFormat($node['store_price']); } private function check($node) : bool { if(empty($node['product_name'])) return false; if(empty($node['plat_code'])) return false; if(empty($node['store_code'])) return false; if($node['product_amount'] <= 0) return false; if($node['mch_id'] <= 0) return false; if($node['store_id'] <= 0) return false; if(empty($node['mch_price'])) return false; if(empty($node['store_price'])) return false; return true; } public function produce() { [$succ,$msg] = $this->mk_plat_code(); if(!$succ) { return [false,$msg]; } [$succ,$msg] = $this->mk_store_code(); if(!$succ) { return [false,$msg]; } [$succ,$msg] = $this->set_mch_price(); if(!$succ) { return [false,$msg]; } return [true,'']; } private function mk_plat_code() { $isExiter = function ($mod_third,$pcode) { $item = $mod_third->findThirdProduct($pcode); return !empty($item); }; $val = [ 'system_code' => $this->plat_code, 'product_name' => $this->product_name, 'refill_amount' => $this->product_amount, 'product_type' => ThirdOnlineProduct ]; $mod_third = Model('refill_third'); if ($isExiter($mod_third, $this->plat_code)) { $ret = $mod_third->editThirdProduct($this->plat_code, $val); } else { $ret = $mod_third->addThirdProduct($val); } return [true,$ret]; } private function mk_store_code() { $channel_namer = function ($store_id) { $mod = Model('refill_provider'); $item = $mod->getProviderInfo(['store_id' => $store_id]); if(empty($item)) { return false; } else { return $item['name']; } }; $good_finder = function ($chname) { global $config; $cfg_map = $config['third_providers']; $goods_id = 0; foreach ($cfg_map as $cfg) { if($cfg['name'] != $chname) continue; $goods_id = $cfg['cfg']['amount'][100][0]['goods_id']; } return $goods_id; }; $isExister = function ($store_id,$sys_code,$goods_id) { $mod = Model('refill_third'); $item = $mod->table('third_proprice')->where(['store_id' => $store_id,'system_code' => $sys_code,'goods_id' => $goods_id])->find(); return !empty($item); }; $store_product_add = function ($ch_name,$goods_id,$fExist) { $val['channel_name'] = $ch_name; $val['store_id'] = $this->store_id; $val['channel_product_name'] = $this->product_name; $val['goods_id'] = $goods_id; $val['channel_code'] = $this->store_code; $val['channel_amount'] = $this->store_price; $val['recharge_type'] = 1; //直冲 $val['system_code'] = $this->plat_code; $val['product_type'] = ThirdOnlineProduct; $mod = Model('refill_third'); if($fExist) { $ret = $mod->edit_provider_product($this->store_id,$this->plat_code,$goods_id,$val); } else { $ret = $mod->addProviderProduct($val); } return $ret; }; $ch_name = $channel_namer($this->store_id); if(empty($ch_name)) { return [false,'无法找到通道名称.']; } $goods_id = $good_finder($ch_name); if($goods_id == 0) { return [false,'无法找到通道对应的goods id.']; } $fExist = $isExister($this->store_id, $this->plat_code, $goods_id); $ret = $store_product_add($ch_name,$goods_id,$fExist); return [true,$ret]; } private function set_mch_price() { $isExist = function ($mchid,$pcode) { $item = Model('')->table('merchant_price') ->where(['mchid' => $mchid, 'quality' => 1, 'pcode' => $pcode])->find(); return !empty($item); }; $model_merchant = Model('merchant'); $val['mchid'] = $this->mch_id; $val['spec'] = $this->product_amount; $val['price'] = $this->mch_price; $val['card_types'] = ThirdRefillCard; $val['quality'] = 1; $val['pcode'] = $this->plat_code; if (!$isExist($this->mch_id, $this->plat_code)) { $ret = $model_merchant->table('merchant_price')->insert($val); } else { $ret = $model_merchant->table('merchant_price') ->where(['mchid' => $this->mch_id, 'quality' => 1, 'pcode' => $this->plat_code]) ->update($val); } return [true,$ret]; } }