11 changed files with 294 additions and 2 deletions
-
2app/Constants/ErrorCode.php
-
6app/Constants/SsdbKeysPrefix.php
-
30app/Controller/StoreController.php
-
49app/Model/Store.php
-
83app/Request/StoreApplyEntryRequest.php
-
8app/Service/AttachmentService.php
-
104app/Service/StoreService.php
-
11app/Service/StoreServiceInterface.php
-
1config/autoload/dependencies.php
-
1config/autoload/middlewares.php
-
1config/routes.php
@ -1,10 +1,57 @@ |
|||||
<?php |
<?php |
||||
|
|
||||
|
declare (strict_types=1); |
||||
namespace App\Model; |
namespace App\Model; |
||||
|
|
||||
|
/** |
||||
|
*/ |
||||
class Store extends Model |
class Store extends Model |
||||
{ |
{ |
||||
|
/** |
||||
|
* The table associated with the model. |
||||
|
* |
||||
|
* @var string |
||||
|
*/ |
||||
protected $table = 'ims_cjdc_store'; |
protected $table = 'ims_cjdc_store'; |
||||
public $timestamps = false; |
|
||||
|
/** |
||||
|
* The attributes that are mass assignable. |
||||
|
* |
||||
|
* @var array |
||||
|
*/ |
||||
|
protected $fillable = [ |
||||
|
'name', |
||||
|
'market_id', |
||||
|
'md_type', |
||||
|
'address', |
||||
|
'coordinates', |
||||
|
'details', |
||||
|
'link_name', |
||||
|
'link_tel', |
||||
|
'logo', |
||||
|
'fm_img', |
||||
|
'zm_img', |
||||
|
'yyzz', |
||||
|
'user_id', |
||||
|
'sq_id', |
||||
|
'admin_id', |
||||
|
'rz_time', |
||||
|
'mm_user_id', |
||||
|
'sq_time', |
||||
|
'rzdq_time', |
||||
|
'state', |
||||
|
'is_open', |
||||
|
'money', |
||||
|
'code', |
||||
|
'uniacid', |
||||
|
'zf_state', |
||||
|
]; |
||||
|
/** |
||||
|
* The attributes that should be cast to native types. |
||||
|
* |
||||
|
* @var array |
||||
|
*/ |
||||
|
protected $casts = []; |
||||
|
|
||||
|
public $timestamps=false; |
||||
|
|
||||
} |
} |
||||
@ -0,0 +1,83 @@ |
|||||
|
<?php |
||||
|
|
||||
|
declare(strict_types=1); |
||||
|
|
||||
|
namespace App\Request; |
||||
|
|
||||
|
use Hyperf\Validation\Request\FormRequest; |
||||
|
|
||||
|
class StoreApplyEntryRequest extends FormRequest |
||||
|
{ |
||||
|
/** |
||||
|
* Determine if the user is authorized to make this request. |
||||
|
*/ |
||||
|
public function authorize(): bool |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Get the validation rules that apply to the request. |
||||
|
*/ |
||||
|
public function rules(): array |
||||
|
{ |
||||
|
return [ |
||||
|
'name' => 'required|nonempty', |
||||
|
'market_id' => 'required|nonempty|integer', |
||||
|
'md_type' => 'required|nonempty|integer', |
||||
|
'address' => 'required|nonempty', |
||||
|
'coordinates' => 'required|nonempty', |
||||
|
'details' => 'required|nonempty', |
||||
|
'link_name' => 'required|nonempty', |
||||
|
'link_tel' => 'required|nonempty|tel', |
||||
|
'logo' => 'required|nonempty|image_if_file', |
||||
|
'fm_img' => 'required|nonempty|image_if_file|file_different_if_file:zm_img', |
||||
|
'zm_img' => 'required|nonempty|image_if_file|file_different_if_file:fm_img', |
||||
|
'yyzz' => 'required|nonempty|image_if_file', |
||||
|
'user_id' => 'required|nonempty|integer', |
||||
|
'rz_time' => 'required|nonempty|integer', |
||||
|
'mm_user_id' => 'nonempty|integer', |
||||
|
'id' => 'nonempty|integer', |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
public function messages(): array |
||||
|
{ |
||||
|
return [ |
||||
|
'*.nonempty' => ':attribute参数异常', |
||||
|
'logo.image' => ':attribute不是正常的图片', |
||||
|
'logo.*' => ':attribute未选择', |
||||
|
'fm_img.image' => ':attribute不是正常的图片', |
||||
|
'fm_img.file_different_if_file' => '身份证正反面不能相同', |
||||
|
'fm_img.*' => ':attribute未选择', |
||||
|
'zm_img.image' => ':attribute不是正常的图片', |
||||
|
'zm_img.file_different_if_file' => '身份证正反面不能相同', |
||||
|
'zm_img.*' => ':attribute未选择', |
||||
|
'yyzz.image' => ':attribute不是正常的图片', |
||||
|
'yyzz.*' => ':attribute未选择', |
||||
|
'link_tel.tel' => ':attribute格式不正确', |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
public function attributes(): array |
||||
|
{ |
||||
|
return [ |
||||
|
'name' => '商户名', |
||||
|
'market_id' => '市场ID', |
||||
|
'md_type' => '门店类型', |
||||
|
'address' => '门店地址', |
||||
|
'coordinates' => '门店经纬度', |
||||
|
'details' => '门店简介', |
||||
|
'link_name' => '联系人姓名', |
||||
|
'link_tel' => '联系人电话', |
||||
|
'logo' => '商户LOGO', |
||||
|
'fm_img' => '商户身份证反面', |
||||
|
'zm_img' => '商户身份证正面', |
||||
|
'yyzz' => '商户营业执照', |
||||
|
'user_id' => '申请用户ID', |
||||
|
'rz_time' => '入驻天数', |
||||
|
'mm_user_id' => '市场经理用户ID', |
||||
|
'id' => '门店ID', |
||||
|
]; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,104 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Service; |
||||
|
|
||||
|
use App\Constants\LogLabel; |
||||
|
use App\Constants\SsdbKeysPrefix; |
||||
|
use App\Model\Store; |
||||
|
use App\TaskWorker\SSDBTask; |
||||
|
use Hyperf\DbConnection\Db; |
||||
|
use Hyperf\Di\Annotation\Inject; |
||||
|
use Hyperf\HttpMessage\Upload\UploadedFile; |
||||
|
use Hyperf\Utils\ApplicationContext; |
||||
|
use League\Flysystem\Filesystem; |
||||
|
|
||||
|
class StoreService implements StoreServiceInterface |
||||
|
{ |
||||
|
/** |
||||
|
* @Inject |
||||
|
* @var AttachmentServiceInterface |
||||
|
*/ |
||||
|
protected $attachmentService; |
||||
|
|
||||
|
/** |
||||
|
* @Inject |
||||
|
* @var Filesystem |
||||
|
*/ |
||||
|
protected $filesystem; |
||||
|
|
||||
|
public function entry($data) |
||||
|
{ |
||||
|
Db::beginTransaction(); |
||||
|
try { |
||||
|
|
||||
|
// 文件上传
|
||||
|
if ($data['logo'] instanceof UploadedFile) { |
||||
|
$data['logo'] = $this->attachmentService->formUpload($data['logo'], 'storelogo', $this->filesystem); |
||||
|
} |
||||
|
|
||||
|
if ($data['fm_img'] instanceof UploadedFile) { |
||||
|
$data['fm_img'] = $this->attachmentService->formUpload($data['fm_img'], 'idcard', $this->filesystem); |
||||
|
} |
||||
|
|
||||
|
if ($data['zm_img'] instanceof UploadedFile) { |
||||
|
$data['zm_img'] = $this->attachmentService->formUpload($data['zm_img'], 'idcard', $this->filesystem); |
||||
|
} |
||||
|
|
||||
|
if ($data['yyzz'] instanceof UploadedFile) { |
||||
|
$data['yyzz'] = $this->attachmentService->formUpload($data['yyzz'], 'storelicense', $this->filesystem); |
||||
|
} |
||||
|
|
||||
|
// 商户信息入库(需审核)
|
||||
|
$store = Store::query()->updateOrCreate( |
||||
|
['id' => $data['id']], |
||||
|
[ |
||||
|
'name' => $data['name'], |
||||
|
'market_id' => $data['market_id'], |
||||
|
'md_type' => $data['md_type'], |
||||
|
'address' => $data['address'], |
||||
|
'coordinates' => $data['coordinates'], |
||||
|
'details' => $data['details'], |
||||
|
'link_name' => $data['link_name'], |
||||
|
'link_tel' => $data['link_tel'], |
||||
|
'tel' => $data['link_tel'], |
||||
|
'logo' => $data['logo'], |
||||
|
'fm_img' => $data['fm_img'], |
||||
|
'zm_img' => $data['zm_img'], |
||||
|
'yyzz' => $data['yyzz'], |
||||
|
'user_id' => $data['user_id'], |
||||
|
'sq_id' => $data['user_id'], |
||||
|
'admin_id' => $data['user_id'], |
||||
|
'rz_time' => $data['rz_time'], |
||||
|
'mm_user_id' => $data['mm_user_id'], |
||||
|
'sq_time' => date('Y-m-d H:i:s'), |
||||
|
'rzdq_time' => date('Y-m-d H:i:s', time() + 1000 * 24 * 3600), |
||||
|
'state' => 1, |
||||
|
'is_open' => 1, |
||||
|
'money' => 0, |
||||
|
'code' => time() . rand(1000, 9999) . $data['user_id'], |
||||
|
'uniacid' => 2, |
||||
|
'zf_state' => 2, |
||||
|
] |
||||
|
); |
||||
|
|
||||
|
Db::commit(); |
||||
|
|
||||
|
// 商户新用户等统计信息入SSDB
|
||||
|
$ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); |
||||
|
|
||||
|
if (!$ssdb->exec('hexists', SsdbKeysPrefix::STORE_NEW_USER.$store->id, 'count')) { |
||||
|
if(false === $ssdb->exec('hset', SsdbKeysPrefix::STORE_NEW_USER.$store->id, ['count', 0])) { |
||||
|
$this->log->event( |
||||
|
LogLabel::SSDB_LOG, |
||||
|
['method' => 'hset-'.SsdbKeysPrefix::STORE_NEW_USER.$store->id, 'key' => SsdbKeysPrefix::STORE_NEW_USER.$store->id] |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} catch (\Exception $e) { |
||||
|
Db::rollBack(); |
||||
|
return $e->getMessage(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Service; |
||||
|
|
||||
|
interface StoreServiceInterface |
||||
|
{ |
||||
|
/** |
||||
|
* 入驻 |
||||
|
*/ |
||||
|
public function entry($data); |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue