TestCommand.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Exports\Dwbs\ShopOrderExport;
  4. use App\Jobs\Dwbs\ImportOrderJob;
  5. use App\Repositories\Enums\Dwbs\DayTypeEnum;
  6. use App\Repositories\Enums\Dwbs\StatisticalResourceTypeEnum;
  7. use App\Repositories\Enums\ModelStatusEnum;
  8. use App\Repositories\Enums\ResponseCodeEnum;
  9. use App\Repositories\Models\Base\User;
  10. use App\Repositories\Models\Dwbs\Good;
  11. use App\Repositories\Models\Dwbs\Order;
  12. use App\Repositories\Models\Dwbs\OrderGood;
  13. use App\Repositories\Models\Dwbs\Ranking;
  14. use App\Repositories\Models\Dwbs\ShopGood;
  15. use App\Repositories\Models\Dwbs\ShopOrder;
  16. use App\Repositories\Models\Dwbs\ShopOrderGood;
  17. use App\Repositories\Models\Dwbs\StatisticalResource;
  18. use App\Repositories\Models\Dwbs\UserJifen;
  19. use App\Repositories\Models\Dwbs\UserXuefen;
  20. use App\Repositories\Models\Dwbs\Zhengshu;
  21. use App\Services\Dwbs\WechatTemplateMessageService;
  22. use App\Support\Sdk\Express\Express;
  23. use Carbon\Carbon;
  24. use EasyWeChat\Factory;
  25. use Illuminate\Console\Command;
  26. use Illuminate\Support\Facades\Cache;
  27. use Illuminate\Support\Facades\Crypt;
  28. use Illuminate\Support\Facades\DB;
  29. use Illuminate\Support\Facades\Http;
  30. use Illuminate\Support\Facades\Redis;
  31. use Illuminate\Support\Facades\Storage;
  32. use Illuminate\Support\Str;
  33. use Intervention\Image\Facades\Image;
  34. use Overtrue\EasySms\PhoneNumber;
  35. use Vinkla\Hashids\Facades\Hashids;
  36. /**
  37. * Class PresenterCommand
  38. * @package Prettus\Repository\Generators\Commands
  39. * @author Anderson Andrade <contato@andersonandra.de>
  40. */
  41. class TestCommand extends Command
  42. {
  43. /**
  44. * The name of command.
  45. *
  46. * @var string
  47. */
  48. protected $name = 'mead:test';
  49. /**
  50. * The description of command.
  51. *
  52. * @var string
  53. */
  54. protected $description = 'test';
  55. /**
  56. * The type of class being generated.
  57. *
  58. * @var string
  59. */
  60. protected $type = 'permission';
  61. /**
  62. * Execute the command.
  63. *
  64. * @return void
  65. * @see fire()
  66. */
  67. public function handle()
  68. {
  69. // $this->exportShopOrder();
  70. // $day = "2024-10-27";
  71. // $firstDayOfWeek = Carbon::now()->startOfMonth();
  72. // dd($firstDayOfWeek);
  73. //// dd($firstDayOfWeek);
  74. // if (Carbon::parse($day)->isSameDay($firstDayOfWeek)) {
  75. // $startTimeTxt = Carbon::parse($day)->startOfWeek()->format('Y年m月d日 H:i');
  76. // $endTimeTxt = Carbon::parse($day)->endOfWeek()->format('Y年m月d日 H:i');
  77. // $timeTxt = "{$startTimeTxt}-{$endTimeTxt}";
  78. // dd($timeTxt);
  79. // }
  80. // $bg = base_path('Data/huojian_bg.png');
  81. // $image = Image::make($bg)->resize(375, 646);
  82. //
  83. // $nickname = '你好你好你好...';
  84. // self::addText($image, $nickname, 375 / 2, 210, 40, 'F00');
  85. // $day = date('Y-m-d');
  86. //
  87. // self::addText($image, Carbon::parse($day)->format('Y年m月d日'), 375 / 2, 458, 16, '3d3d3d');
  88. // $dir = "huojianImg/" . $day;
  89. // $filename = Str::random() . '.png';
  90. // $filename = 'mead.png';
  91. //
  92. //
  93. // Storage::disk('public')->put("{$dir}/{$filename}.txt", 1);
  94. // $path = Storage::disk('public')->path("{$dir}/{$filename}");
  95. // $image->save($path);
  96. //
  97. // Storage::disk('public')->delete("{$dir}/{$filename}.txt");
  98. // $this->testOrderData();
  99. // $this->makeUserOrder(4, 1);
  100. // User::refreshUserTag(4);
  101. // $this->makeUserOrder(4, 1);
  102. // WechatTemplateMessageService::sendAddXuefen(4, 1);
  103. // $this->areaToBase();
  104. // ShopOrder::query()->truncate();
  105. // ShopGood::query()->update(['nums' => 3, 'duihuan_nums' => 0]);
  106. // ShopOrderGood::query()->truncate();
  107. //
  108. // Cache::flush();
  109. // $goods = ShopGood::query()->get();
  110. // foreach ($goods as $good) {
  111. // ShopGood::updateKuCun($good->id, $good->nums);
  112. // }
  113. //
  114. // $a = Cache::increment("mead:nums");
  115. // Cache::decrement("mead:nums", $a);
  116. // ShopGood::addGoodNums(1, 1, 2);
  117. // $url = '/admin/base/auth/login';
  118. // dd(strpos($url, "/admin/") == 0);
  119. $this->export('2024-10-01', '2024-12-01', 1000);
  120. $this->line('ok');
  121. }
  122. public function export($start_day, $end_day, $limit = 1000)
  123. {
  124. $users = Ranking::query()->where('day_type', DayTypeEnum::day)->select(['user_id', DB::raw("sum(day_xuefen) as dxf")])->groupBy('user_id')->orderByDesc('dxf')->limit(10)->get();
  125. foreach ($users as $user) {
  126. $gs = OrderGood::query()->where('user_id', $user['user_id'])->select(['user_id', 'good_id', DB::raw('count(nums) as good_nums')])->groupBy('good_id')->pluck('good_nums', 'good_id');
  127. }
  128. }
  129. public function areaToBase()
  130. {
  131. $provinces = json_decode(file_get_contents(base_path('app/Support/Sdk/Address/province.json')), true);
  132. $citys = json_decode(file_get_contents(base_path('app/Support/Sdk/Address/city.json')), true);
  133. $areas = json_decode(file_get_contents(base_path('app/Support/Sdk/Address/area.json')), true);
  134. $sheng = [];
  135. $shi = [];
  136. $qu = [];
  137. foreach ($provinces as $province) {
  138. $sheng[$province['value'] . '0000'] = [
  139. 'name' => $province['label'],
  140. 'pid' => 0,
  141. 'zipcode' => $province['value'] . '0000',
  142. ];
  143. }
  144. file_put_contents(base_path('app/Support/Sdk/Address/province_1.json'), json_encode($sheng, JSON_UNESCAPED_UNICODE));
  145. foreach ($citys as $s) {
  146. foreach ($s as $ss) {
  147. $sc = substr($ss['value'], 0, 2);
  148. $shi[$ss['value'] . '00'] = [
  149. 'name' => $ss['label'],
  150. 'pid' => $sc . '0000',
  151. 'zipcode' => $ss['value'] . '00',
  152. ];
  153. }
  154. }
  155. file_put_contents(base_path('app/Support/Sdk/Address/city_1.json'), json_encode($shi, JSON_UNESCAPED_UNICODE));
  156. foreach ($areas as $s) {
  157. foreach ($s as $ss) {
  158. foreach ($ss as $sss) {
  159. $sc = substr($sss['value'], 0, 4);
  160. $qu[$sss['value']] = [
  161. 'name' => $sss['label'],
  162. 'pid' => $sc . '00',
  163. 'zipcode' => $sss['value'],
  164. ];
  165. }
  166. }
  167. }
  168. file_put_contents(base_path('app/Support/Sdk/Address/area_1.json'), json_encode($qu, JSON_UNESCAPED_UNICODE));
  169. }
  170. public function makeUserOrder($user_id, $order_nums = 1)
  171. {
  172. $users = User::query()->where('id', $user_id)->get();
  173. $tx = 0;
  174. foreach ($users as $user) {
  175. for ($o = 1; $o <= $order_nums; $o++) {
  176. $txf = random_int(1, 3);
  177. $da = [];
  178. $goods = Good::query()->inRandomOrder()->limit($txf)->get();
  179. foreach ($goods as $good) {
  180. $num = random_int(1, 5);
  181. $da[] = [
  182. 'ProductGroupID' => 9,
  183. 'ProductGroupSKUID' => 9,
  184. 'ProductName' => "大卫博士罐装内裤(青春版)",
  185. 'ProductCode' => $good['name'],
  186. 'SKUCode' => "青春版",
  187. 'AttributesVales' => [],
  188. 'Qty' => $num,
  189. ];
  190. $tx += $num * $good['xuefen'];
  191. }
  192. $data = [
  193. 'Type' => 1,
  194. 'RetailID' => 134,
  195. 'Code' => Order::makeNo(),
  196. 'AuthorizationCode' => $user->code,
  197. 'Domain' => "http://hnsystemse.njjinhao.top/",
  198. 'data' => $da
  199. ];
  200. dispatch(new ImportOrderJob(json_encode($data, true)));
  201. }
  202. $this->line($tx);
  203. }
  204. }
  205. public function testOrderData()
  206. {
  207. //{"Type":1,"RetailID":134,"Code":"2024102947561000002","Domain":"http://hnsystemse.njjinhao.top/","data":[{"ProductGroupID":9,"ProductGroupSKUID":9,"ProductName":"大卫博士罐装内裤(青春版)","ProductCode":"青春版","SKUCode":"青春版","AttributesVales":[],"Qty":2}]}
  208. $data = [
  209. 'Type' => 1,
  210. 'RetailID' => 134,
  211. 'Code' => 2024102947561000002,
  212. 'AuthorizationCode' => 'M100001',
  213. 'Domain' => "http://hnsystemse.njjinhao.top/",
  214. 'data' => [
  215. [
  216. 'ProductGroupID' => 9,
  217. 'ProductGroupSKUID' => 9,
  218. 'ProductName' => "大卫博士罐装内裤(青春版)",
  219. 'ProductCode' => "青春版",
  220. 'SKUCode' => "青春版",
  221. 'AttributesVales' => [],
  222. 'Qty' => 2,
  223. ]
  224. ]
  225. ];
  226. dispatch(new ImportOrderJob(json_encode($data, true)));
  227. }
  228. public static function addText(&$bgImage, $text, $x, $y, $size, $color, $align = 'center', $valign = 'middle', $ziti = '')
  229. {
  230. if (!$ziti) $ziti = base_path('Data/ziti/ht.otf');
  231. // $y += ($size / 2);
  232. $bgImage->text($text, $x, $y, function ($font) use ($size, $color, $ziti, $align, $valign) {
  233. $font->file($ziti);
  234. $font->size($size);
  235. $font->color($color);
  236. $font->angle(0);
  237. $font->align($align);
  238. $font->valign($valign);
  239. });
  240. // return $bgImage;
  241. }
  242. public function exportShopOrder()
  243. {
  244. $file_name = time() . '.xlsx';
  245. $ids = [2];
  246. (new ShopOrderExport($ids))->store($file_name);
  247. }
  248. }