makeGood.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\command;
  4. use app\admin\model\Unit;use PhpOffice\PhpSpreadsheet\Cell\Coordinate;use PhpOffice\PhpSpreadsheet\IOFactory;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;use think\facade\Db;
  9. class makeGood extends Command
  10. {
  11. protected $db;
  12. protected function configure()
  13. {
  14. // 指令配置
  15. $this->setName('makegood')
  16. ->setDescription('the makegood command');
  17. }
  18. protected function execute(Input $input, Output $output)
  19. {
  20. // 指令输出
  21. $output->writeln('makegood');
  22. $file ="./public/exece.xlsx";
  23. $spreadsheet =IOFactory::load($file);
  24. // 选择第一个工作表
  25. ini_set("memory_limit","-1");
  26. $this->db=Db::connect("mysql_sys");
  27. // $this->getNake();return;
  28. $worksheet = $spreadsheet->getActiveSheet();
  29. $height = $worksheet->getHighestRow();
  30. // 获取最高的列号
  31. $highestColumn = $worksheet->getHighestColumn();
  32. $number = Coordinate::columnIndexFromString($highestColumn);
  33. $header=[
  34. '',
  35. 'spuCode',
  36. 'good_name',
  37. 'cat_id',
  38. 'brand_id',
  39. 'good_unit',
  40. 'good_type',
  41. 'companyNo',
  42. 'moq',
  43. 'customized',
  44. 'tax',
  45. 'supplierNo',
  46. 'is_auth',
  47. 'is_stock',
  48. 'after_sales',
  49. 'craft_desc',
  50. 'good_remark',
  51. 'good_size',
  52. 'weight',
  53. 'packing_way',
  54. 'packing_size',
  55. 'packing_spec',
  56. 'packing_list',
  57. 'packing_weight',
  58. 'good_bar',
  59. 'supply_area',
  60. 'delivery_place',
  61. 'origin_place',
  62. 'delivery_day',
  63. 'lead_time',
  64. 'sample_day',
  65. 'sample_fee',
  66. 'cert_fee',
  67. 'packing_fee',
  68. 'cost_fee',
  69. 'mark_fee',
  70. 'demo_fee',
  71. 'open_fee',
  72. 'noble_metal',
  73. 'noble_weight',
  74. 'is_gold_price',
  75. 'cgd_gold_price',
  76. 'market_price',
  77. 'nake_price',
  78. 'is_step',
  79. 'supplier_origin_price',
  80. 'cgd_supplier_code',
  81. 'cgd_apply_id',
  82. 'cgd_apply_name',
  83. 'is_exclusive',
  84. 'is_diff',
  85. 'config',
  86. 'other_config',
  87. 'stock_moq',
  88. 'is_support_barter',
  89. 'is_combind',
  90. 'plat_code'];
  91. $data=[];
  92. for ($i=2;$i<=$height;$i++){
  93. $temp=[];
  94. for ($j=1;$j<=$number;$j++){
  95. if(isset($header[$j])){
  96. $temp[$header[$j]] = $worksheet->getCellByColumnAndRow($j,$i)->getValue()??'';
  97. }else{
  98. break;
  99. }
  100. }
  101. $temp['spuCode'] = substr(makeNo('SKU'),0,-4).str_pad(strval($i),4,"0",STR_PAD_LEFT);
  102. $temp['companyName'] = $this->getCompanyName($temp['companyNo']);
  103. $temp['supplierName'] = $this->getCompanyName($temp['supplierNo']);
  104. $temp['cgd_supplier_name'] = $this->getCompanyName($temp['cgd_supplier_code']);
  105. $temp['delivery_place']= $this->getAddress($temp['delivery_place']);
  106. $temp['origin_place']= $this->getAddress($temp['origin_place']);
  107. $temp['good_unit']= $this->getUnit($temp['good_unit']);
  108. $data[]=$temp;
  109. if($i%1000==0){
  110. Db::name('good_temp')->insertAll($data);
  111. $data=[];
  112. }
  113. }
  114. if(!empty($data)) Db::name('good_temp')->insertAll($data);
  115. $this->getOnline();
  116. $this->getNake();
  117. }
  118. public function getCompanyName($code){
  119. return $this->db->name("headquarters")->where("code",$code)->value("name",'');
  120. }
  121. public function getUnit($unit_name){
  122. $unit=Unit::where("unit",$unit_name)->findOrEmpty();
  123. if($unit->isEmpty()){
  124. $info =Unit::create(["unit"=>$unit_name]);
  125. return $info->id;
  126. }
  127. return $unit->id;
  128. }
  129. public function getAddress($addr){
  130. $p_c_a =get_address($addr);
  131. $addeRss=[];
  132. $province = Db::name('province')
  133. ->field('province_code,name')
  134. ->where('name', $p_c_a['province'])
  135. ->findOrEmpty();
  136. $addeRss[]=$province['province_code'];
  137. $city = Db::name('city')
  138. ->field('city_code,name')
  139. ->where(['name' => $p_c_a['city']?:$p_c_a['province'], 'province_code' => $province['province_code'] ?: ''])
  140. ->findOrEmpty();
  141. $addeRss[]=$city['city_code']?? $province['province_code'];
  142. $area = Db::name('area')
  143. ->field('area_code,name')
  144. ->where(['name' => $p_c_a['district'], 'city_code' => $city['city_code'] ?:''])
  145. ->findOrEmpty();
  146. $addeRss[]= $area['area_code']?? '';
  147. return implode(",",$addeRss);
  148. }
  149. public function getOnline(){
  150. $file ='./public/add.xlsx';
  151. $spreadsheet =IOFactory::load($file);
  152. $worksheet = $spreadsheet->getActiveSheet();
  153. $height = $worksheet->getHighestRow();
  154. // 获取最高的列号
  155. $highestColumn = $worksheet->getHighestColumn();
  156. $number = Coordinate::columnIndexFromString($highestColumn);
  157. $data=[];
  158. $header=["",'spuCode','skuCode','platform_code','is_compliance','compliance_remark','plat_code','is_fixed'];
  159. for ($i=2;$i<=$height;$i++){
  160. $temp=[];
  161. for ($j=1;$j<=$number;$j++){
  162. if(isset($header[$j])){
  163. $temp[$header[$j]] = $worksheet->getCellByColumnAndRow($j,$i)->getValue()??'';
  164. }else{
  165. break;
  166. }
  167. }
  168. $temp['spuCode'] = Db::name("good_temp")->where(["plat_code"=>$temp['plat_code']])->value("spuCode",'');
  169. $temp['skuCode'] = substr(makeNo('SN'),0,-4).str_pad(strval($i),4,'0',STR_PAD_LEFT);
  170. $data[]=$temp;
  171. if($i%1000==0){
  172. Db::name('good_platform_temp')->insertAll($data);
  173. $data=[];
  174. }
  175. }
  176. if(!empty($data)) Db::name('good_platform_temp')->insertAll($data);
  177. $this->getLadder();
  178. }
  179. public function getLadder(){
  180. $file ='./public/ladder.xlsx';
  181. $spreadsheet =IOFactory::load($file);
  182. $worksheet = $spreadsheet->getActiveSheet();
  183. $height = $worksheet->getHighestRow();
  184. // 获取最高的列号
  185. $highestColumn = $worksheet->getHighestColumn();
  186. $number = Coordinate::columnIndexFromString($highestColumn);
  187. $data=[];
  188. $header=['','skuCode','min_num','sale_price','origin_price','market_price','market_platform','origin_rate','cost_fee','plat_code'];
  189. for ($i=2;$i<=$height;$i++){
  190. $temp=[];
  191. for ($j=1;$j<=$number;$j++){
  192. if(isset($header[$j])){
  193. $temp[$header[$j]] = $worksheet->getCellByColumnAndRow($j,$i)->getValue()??'';
  194. }else{
  195. break;
  196. }
  197. }
  198. $temp['skuCode'] = Db::name('good_platform_temp')->where(['plat_code'=>$temp['plat_code']])->value('skuCode','');
  199. $data[]=$temp;
  200. if($i%1000==0){
  201. Db::name('good_ladder_temp')->insertAll($data);
  202. $data=[];
  203. }
  204. }
  205. if(!empty($data))Db::name('good_ladder_temp')->insertAll($data);
  206. }
  207. public function getNake(){
  208. $file ='./public/nake.xlsx';
  209. $spreadsheet =IOFactory::load($file);
  210. $worksheet = $spreadsheet->getActiveSheet();
  211. $height = $worksheet->getHighestRow();
  212. // 获取最高的列号
  213. $highestColumn = $worksheet->getHighestColumn();
  214. $number = Coordinate::columnIndexFromString($highestColumn);
  215. $data=[];
  216. $header=['','spuCode','min_num','nake_fee','cost_fee','delivery_fee','cert_fee','mark_fee','package_fee','other_fee','nake_total','plat_code'];
  217. for ($i=2;$i<=$height;$i++){
  218. $temp=[];
  219. for ($j=1;$j<=$number;$j++){
  220. if(isset($header[$j])){
  221. $temp[$header[$j]] = $worksheet->getCellByColumnAndRow($j,$i)->getValue()??'';
  222. }else{
  223. break;
  224. }
  225. }
  226. $temp['spuCode'] = Db::name('good_temp')->where(['plat_code'=>$temp['plat_code']])->value('spuCode','');
  227. $data[]=$temp;
  228. if($i%1000==0){
  229. Db::name('good_nake_temp')->insertAll($data);
  230. $data=[];
  231. }
  232. }
  233. if(!empty($data))Db::name('good_nake_temp')->insertAll($data);
  234. }
  235. }