good.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\command;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\input\Argument;
  7. use think\console\input\Option;
  8. use think\console\Output;
  9. use think\facade\Db;
  10. class good extends Command
  11. {
  12. private $db;
  13. protected function configure()
  14. { $this->setName('good')
  15. ->setDescription('the good command');
  16. }
  17. protected function execute(Input $input, Output $output)
  18. {
  19. $this->db =Db::connect("mysql2");
  20. $data = $this->Getdata();
  21. foreach ($data as $value){
  22. $value['spucode']= str_replace("GY","SPU",$value['good_code']);
  23. $value['item_code']=str_replace("GY","SKU",$value['good_code']);
  24. $isT=Db::name("good")->where("good_code","=",$value['good_code'])->find();
  25. $temp=[
  26. "spuCode"=>$value['spucode'],
  27. "good_code"=>$value['good_code'],
  28. "createrid"=>0,
  29. "ownerid"=>0,
  30. "cgderid"=>0,
  31. "creater"=>$value['creater']??"",
  32. "owner"=>$value['owner']??"",
  33. "cgder"=>$value['cg_saler']==""?"":$value['cg_saler'],
  34. "gys_code"=>$value['gys_code'],
  35. "license"=>'',
  36. "platform_code"=>$value['item']??"",
  37. "cat_id"=>$this->getCat($value['sort_f'],$value['sort_s'],$value['sort_t']),
  38. "addtime"=>isset($value['addtime'])&&$value['addtime']!=""? $value['addtime']:date("Y-m-d H:i:s"),
  39. "updatetime"=>isset($value['updatetime'])&&$value['updatetime']!=""? $value['updatetime']:date("Y-m-d H:i:s"),
  40. ];
  41. if($isT){
  42. Db::name("good")->where($isT)->save($temp);
  43. }else{
  44. Db::name("good")->save($temp);
  45. }
  46. $this->addType($value);
  47. $this->laddle($value);
  48. }
  49. }
  50. public function laddle($value){
  51. if($value['step_num_1']!=""){
  52. $temp=[
  53. "skuCode"=>$value['item_code'],
  54. "platform_code"=>$value['item']??"",
  55. "min_num"=>$value['step_num_1'],
  56. "max_num"=>$value['step_num_2']??0,
  57. "sale_price"=>$value['step_price_1'],
  58. "origin_price"=>$value['market_fee'],
  59. "ladder"=>1,
  60. "addtime"=>date("Y-m-d H:i:s"),
  61. "updatetime"=>date("Y-m-d H:i:s")
  62. ];
  63. $upda= Db::name("good_ladder")->where(["skuCode"=>$value['item_code'],"platform_code"=>$temp['platform_code'],"ladder"=>$temp['ladder']])->find();
  64. if($upda){
  65. Db::name("good_ladder")->where($upda)->save($temp);
  66. }else{
  67. Db::name("good_ladder")->save($temp);
  68. }
  69. }
  70. if($value['step_num_2']!=""){
  71. $temp=[
  72. "skuCode"=>$value['item_code'],
  73. "platform_code"=>$value['item']??"",
  74. "min_num"=>$value['step_num_2'],
  75. "max_num"=>$value['step_num_3']??0,
  76. "sale_price"=>$value['step_price_2'],
  77. "origin_price"=>$value['market_fee'],
  78. "ladder"=>2,
  79. "addtime"=>date("Y-m-d H:i:s"),
  80. "updatetime"=>date("Y-m-d H:i:s")
  81. ];
  82. $upda= Db::name("good_ladder")->where(["skuCode"=>$value['item_code'],"platform_code"=>$temp['platform_code'],"ladder"=>$temp['ladder']])->find();
  83. if($upda){
  84. Db::name("good_ladder")->where($upda)->save($temp);
  85. }else{
  86. Db::name("good_ladder")->save($temp);
  87. }
  88. }
  89. if($value['step_num_3']!=""){
  90. $temp=[
  91. "skuCode"=>$value['item_code'],
  92. "platform_code"=>$value['item']??"",
  93. "min_num"=>$value['step_num_3'],
  94. "max_num"=>0,
  95. "sale_price"=>$value['step_price_3'],
  96. "origin_price"=>$value['market_fee'],
  97. "ladder"=>3,
  98. "addtime"=>date("Y-m-d H:i:s"),
  99. "updatetime"=>date("Y-m-d H:i:s")
  100. ];
  101. $upda= Db::name("good_ladder")->where(["skuCode"=>$value['item_code'],"platform_code"=>$temp['platform_code'],"ladder"=>$temp['ladder']])->find();
  102. if($upda){
  103. Db::name("good_ladder")->where($upda)->save($temp);
  104. }else{
  105. Db::name("good_ladder")->save($temp);
  106. }
  107. }
  108. }
  109. public function getCat($f,$s,$t){
  110. if($f==''){
  111. return 0;
  112. }
  113. $first = Db::name("cat")->where(['cat_name'=>$f,"level"=>1])->find();
  114. if(empty($first)){
  115. return 0;
  116. }
  117. if($s==""){
  118. return $first['id'];
  119. }
  120. $sec = Db::name("cat")->where(['cat_name'=>$s,"level"=>2,"pid"=>$first['id']])->find();
  121. if(empty($sec)){
  122. return $first['id'];
  123. }
  124. if($t==""){
  125. return $sec['id'];
  126. }
  127. $thd = Db::name("cat")->where(['cat_name'=>$t,"level"=>3,"pid"=>$sec['id']])->find();
  128. if(empty($thd)){
  129. return $sec['id'];
  130. }
  131. return $thd['id'];
  132. }
  133. public function addType($value){
  134. $data=[
  135. "skuCode"=>$value['item_code'],
  136. "spuCode"=>$value['spucode'],
  137. "good_name"=>$value['good_name'],
  138. "good_desc"=>'',
  139. "good_img"=>'',
  140. "good_type"=>$value['good_type'],
  141. "good_title"=>'',
  142. "barnd"=>$value['brand'],
  143. "model"=>$value['model'],
  144. "origin_place"=>$value['good_addr'],
  145. "unit"=>$value['unit'],
  146. "weight"=>$value['good_weight'],
  147. "color"=>$value['color']??'',
  148. "material"=>$value['material']??'',
  149. "craft_desc"=>'',
  150. "specs"=>$value['specs'],
  151. "good_size"=>"",
  152. "packing_size"=>$value['pack_size'],
  153. "packing_way"=>"",
  154. "packing_specs"=>"",
  155. "packing_weight"=>"0",
  156. "bar_code"=>$value['bar_code'],
  157. "supply_area"=>$value['supply_area'],
  158. "packing_img"=>"",
  159. "delivery_place"=>$value['shipment'],
  160. "delivery_day"=>intval($value['logistics']),
  161. "market_price"=>$value['market_fee'],
  162. "warn_stock"=>0,
  163. "web_url"=>"",
  164. "is_diff"=>$value['is_diff']=="是"?1 :0,
  165. "cert_fee"=>$value['cert_fee']??0,
  166. "packing_fee"=>$value['packing_fee']??0,
  167. "mark_fee"=>$value['mark_fee']??0,
  168. "cost_fee"=>$value['cost_fee']??0,
  169. "demo_fee"=>0,
  170. "noble_metal"=>$value['noble_metal'],
  171. "open_fee"=>0,
  172. "response_time"=>intval($value['fk_day']),
  173. "lead_time"=>intval($value['duration']),
  174. "custom_moq"=>intval($value['min_num']),
  175. "custome_day"=>0,
  176. "sample_day"=>intval($value['sampling_period']),
  177. "sample_fee"=>floor($value['sample_fee']),
  178. "nake_price"=>$value['nake_fee'],
  179. "addtime"=>date("Y-m-d H:i:s"),
  180. "updatetime"=>date("Y-m-d H:i:s")
  181. ];
  182. $ist = Db::name("good_type")->where(["skuCode"=>$data['skuCode']])->find();
  183. if($ist){
  184. Db::name("good_type")->where($ist)->save($data);
  185. }else{
  186. Db::name("good_type")->save($data);
  187. }
  188. }
  189. public function Getplat($name){
  190. $plat=Db::name("platform")->where(["paltform_name"=>$name])->find();
  191. return isset($plat['paltform_code'])&&$plat['paltform_code']!='' ?$plat['paltform_code']:$name;
  192. }
  193. public function Getdata(){
  194. $date = date("Y-m-d H:i:s",strtotime("-1 day"));
  195. $sql="SELECT
  196. b.Date1618678149288 as 'addtime',
  197. b.ShortText1621438752474 as 'good_code',
  198. b.ShortText1615776172238 as 'item',
  199. (SELECT
  200. b_.`name`
  201. FROM
  202. h_org_user b_
  203. WHERE b_.id =b.creater) as 'creater',
  204. (SELECT
  205. b_.`name`
  206. FROM
  207. h_org_user b_
  208. WHERE b_.id =b.`owner`) as 'owner',
  209. b.text1615776332933 as 'good_name',
  210. b.ShortText1622973543024 as 'old_item',
  211. b.ShortText1618630964434 as 'tkcode',
  212. b.text1615776271768 as 'item_code',
  213. b.text1618981719029 as 'spucode',
  214. b.text1615776440661 as 'model',
  215. b.text1615776695388 as 'color',
  216. b.text1615776685415 as 'material',
  217. b.text1618677034797 as 'technology',
  218. b.ShortText1615776786473 as 'unit',
  219. b.text1618677035673 as 'good_type',
  220. b.text1619509430228 as 'specs',
  221. b.ShortText1618677119629 as 'is_main',
  222. b.ShortText1617875730953 as 'is_diff',
  223. ifnull(b.Number1618677207590,0) as 'good_weight',
  224. ifnull(b.Number1619054377997,0) as 'box_weight',
  225. b.ShortText1618677229373 as 'box_specs',
  226. b.text1618677251640 as 'box_size',
  227. b.text1618677252567 as 'pack_size',
  228. b.ShortText1618677280883 as 'bar_code',
  229. b.ShortText1618677293358 as 'good_addr',
  230. b.ShortText1618677303623 as 'fk_day',
  231. b.ShortText1618677324610 as 'supply_area',
  232. b.text1619517580239 as 'shipment',
  233. ifnull(b.ShortText1615776990102,'') as 'gys_code',
  234. b.Number1618677463881 as 'min_num',
  235. b.number1619054436137 as 'order_minnum',
  236. b.Number1617867853654 as 'duration',
  237. b.Number1618677510201 as 'sampling_period',
  238. ifnull(b.Number1618677523586,0) as 'sample_fee',
  239. ifnull(b.number1615788597819,0) as 'nake_fee',
  240. b.number1617867867574 as 'logistics',
  241. ifnull(b.number1615788674789,0) as 'logistics_fee',
  242. ifnull(b.number1615788650916,0) as 'cert_fee',
  243. ifnull(b.number1615788639684,0) as 'packing_fee',
  244. ifnull(b.number1615788611295,0) as 'mark_fee',
  245. ifnull(b.number1617875705335,0) as 'cost_fee',
  246. ifnull(b.number1615788686735,0) as 'unit_price',
  247. ifnull(b.ShortText1615454226082,'') as 'noble_metal',
  248. ifnull(b.number1618677641446,0) as 'metal_weight',
  249. ifnull(b.Number1616399256021,0) as 'market_fee',
  250. b.ShortText1616119282513 as 'wsm_nature',
  251. b.ShortText1619054472299 as 'is_step',
  252. b.ShortText1618677768792 as 'tax',
  253. b.Number1618677857395 as 'step_num_1',
  254. b.Number1619054496274 as 'step_post_1',
  255. b.Number1618677862829 as 'step_price_1',
  256. b.number1618677888101 as 'step_num_2',
  257. b.number1619054497412 as 'step_post_2',
  258. b.number1618677890766 as 'step_price_2',
  259. b.number1618677920417 as 'step_num_3',
  260. b.number1619054516068 as 'step_post_3',
  261. b.number1618677922828 as 'step_price_3',
  262. b.number1618677997457 as 'sale_1',
  263. b.number1618677998335 as 'sale_2',
  264. b.number1618678013601 as 'sale_3',
  265. b.number1618964483608 as 'sale_other',
  266. (SELECT
  267. b_.`name`
  268. FROM
  269. h_org_user b_
  270. WHERE b_.id = JSON_EXTRACT (
  271. b.StaffSelector1616205980618,
  272. '$[0].id'
  273. )) as 'cg_saler',
  274. b.ShortText1618678061783 as 'is_online',
  275. b.ShortText1618678132819 as 'fund',
  276. b.ShortText1615802884401 as 'brand',
  277. b.ShortText1615776612618 as 'sort_f',
  278. b.text1615776646788 as 'sort_s',
  279. b.ShortText1618558317611 as 'sort_t',
  280. b.ShortText1616222832962 as 'supplier',
  281. b.ShortText1631180192195 as 'change',
  282. b.modifiedTime as 'updatetime'
  283. from ibt0b_SPXX b ";
  284. $result = $this->db->query($sql);
  285. return $result;
  286. }
  287. }