ApproachOrderForm.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. <?php
  2. namespace common\models\forms;
  3. use common\helpers\Cache;
  4. use common\helpers\Date;
  5. use common\components\Model;
  6. use common\helpers\Form;
  7. use common\helpers\LoggerTool;
  8. use common\helpers\PayStack;
  9. use common\helpers\user\Balance;
  10. use common\helpers\user\Cash;
  11. use common\helpers\user\Info;
  12. use common\libs\logging\operate\AdminOperate;
  13. use common\models\ApproachDecOrder;
  14. use common\models\ApproachOrder;
  15. use common\models\ApproachOrderGoods;
  16. use common\models\DealType;
  17. use common\models\DecLevelLog;
  18. use common\models\DecOrder;
  19. use common\models\Order;
  20. use common\models\OrderGoods;
  21. use common\models\Period;
  22. use common\models\ReceiveAddress;
  23. use common\models\Region;
  24. use common\models\ShopGoods;
  25. use common\models\User;
  26. use common\models\UserNetwork;
  27. use yii\base\Exception;
  28. /**
  29. * Login form
  30. */
  31. class ApproachOrderForm extends Model
  32. {
  33. public $sn;
  34. public $expressCompany;
  35. public $orderTrackNo;
  36. public $status;
  37. public $remark;
  38. public $note;
  39. public $type;
  40. public $addressId;
  41. public $payType;
  42. public $goodsId;
  43. public $goodsNum;
  44. public $payPassword;
  45. public $email;
  46. public $userName;
  47. public $consignee;
  48. public $acceptMobile;
  49. public $province;
  50. public $city;
  51. public $county;
  52. public $lgaName;
  53. public $cityName;
  54. public $detailaddress;
  55. private $_address;
  56. private $_decAmount;
  57. private $_decPv;
  58. private $_freight;
  59. private $_payAmount;
  60. private $_orderGoods;
  61. private $_standardAmount;
  62. private $_decAmountStandard;
  63. /**
  64. * @var ApproachOrder
  65. */
  66. private $_model;
  67. public function init() {
  68. parent::init();
  69. $this->adminOperateLogger = new AdminOperate([
  70. 'fetchClass' => ApproachOrder::class,
  71. ]);
  72. }
  73. /**
  74. * @inheritdoc
  75. */
  76. public function rules()
  77. {
  78. return [
  79. [['sn', 'expressCompany', 'orderTrackNo', 'status', 'remark','type','addressId','payType','goodsId','goodsNum', 'payPassword','userName','consignee','acceptMobile','province',/*'city','county',*/'lgaName','cityName','detailaddress','email'], 'trim'],
  80. [['sn', 'expressCompany', 'orderTrackNo', 'status', 'remark','type','addressId','payType','goodsId','goodsNum', 'payPassword','userName','consignee','acceptMobile','province',/*'city','county',*/'detailaddress'/*,'email'*/], 'required'],
  81. [['status'], 'isStatus'],
  82. [['addressId'], 'isAddress'],
  83. [['payType'], 'isPayType'],
  84. [['payPassword'], 'validatePassword'],
  85. ];
  86. }
  87. public function attributeLabels()
  88. {
  89. return [
  90. 'sn' => 'Order code',//订单号
  91. 'expressCompany' => 'ExpressCompany',//快递公司
  92. 'orderTrackNo' => 'courier number',//快递单号
  93. 'status' => 'status',//状态
  94. 'remark' => 'remark',//备注
  95. 'type' => 'order type',//订单类型
  96. 'addressId' => 'addressId',//收货地址
  97. 'payType' => 'payType',//支付方式
  98. 'goodsId' => 'Product ID',
  99. 'goodsNum' => 'Product quantity',//
  100. 'userName' => '复消会员编号',//复消会员编号
  101. 'consignee' => '收货人',//收货人
  102. 'acceptMobile' => '收货电话',//收货电话
  103. 'province' => '省',
  104. 'city' => '市',
  105. 'county' => '区',
  106. 'lgaName' => 'lga name',
  107. 'cityName' => 'City Name',
  108. 'detailaddress' => '收货详细地址',
  109. 'email' => 'Email',
  110. ];
  111. }
  112. /**
  113. * 指定校验场景
  114. * @return array
  115. */
  116. public function scenarios()
  117. {
  118. $parentScenarios = parent::scenarios();
  119. $customScenarios = [
  120. // 管理员修改订单状态
  121. 'adminStatus' => ['sn', 'status'],
  122. // 校验订单支付
  123. 'verifyPayStack' => ['sn', 'note', 'status'],
  124. // 会员下单
  125. 'userOrder' => ['type','addressId', 'payType','goodsId','goodsNum', 'note', 'payPassword'],
  126. ];
  127. return array_merge($parentScenarios, $customScenarios);
  128. }
  129. /**
  130. * 校验之前
  131. * @return bool
  132. */
  133. public function beforeValidate()
  134. {
  135. $parentValidate = parent::beforeValidate();
  136. if ($this->sn) {
  137. $this->_model = ApproachOrder::findOne(['SN' => $this->sn]);
  138. if (!$this->_model){
  139. $this->addError('sn', '订单不存在');
  140. return false;
  141. }
  142. }
  143. if ($this->scenario == 'verifyPayStack'){
  144. if ($this->_model->STATUS != \Yii::$app->params['orderStatus']['notPaid']['value']) {
  145. $this->addError('sn', '订单支付状态错误');
  146. return false;
  147. }
  148. }
  149. return $parentValidate;
  150. }
  151. /**
  152. * 判断收货地址是否存在
  153. * @param $attribute
  154. */
  155. public function isAddress($attribute){
  156. if (!$receiveAddress = ReceiveAddress::find()->where(' ID=:ID', [':ID' => $this->addressId])->asArray()->one()) {
  157. $this->addError($attribute, '收货地址不存在');
  158. } else {
  159. $this->_address = $receiveAddress;
  160. }
  161. }
  162. /**
  163. * 校验支付密码
  164. * @param $attribute
  165. * @param $params
  166. */
  167. public function validatePassword($attribute, $params) {
  168. if (!User::validatePayPassword(\Yii::$app->user->id, $this->payPassword)) {
  169. $this->addError($attribute, '支付密码不正确');
  170. }
  171. }
  172. /**
  173. * 判断支付方式
  174. * @param $attribute
  175. */
  176. public function isPayType($attribute)
  177. {
  178. if ($this->payType != 'pay_stack'){
  179. $this->addError($attribute, '只允许PayStack方式支付');
  180. return;
  181. }
  182. // 一个订单只能包含一类商品
  183. $goods = ShopGoods::find()->select('ID,CATEGORY_TYPE')->where(['in', 'ID', $this->goodsId])->andWhere(['STATUS' => 1])->asArray()->all();
  184. $goodsCategoryType = array_unique(array_column($goods, 'CATEGORY_TYPE'));
  185. if (count($goodsCategoryType) != 1) {
  186. $this->addError($attribute, 'Order cannot contain multiple product categories');//订单不能包含多种商品分类
  187. return;
  188. }
  189. // 购买方式
  190. $sellTypeLabelMap = array_column(ShopGoods::SALE_TYPE, NULL, 'label');
  191. if (!array_key_exists($this->payType, $sellTypeLabelMap)) {
  192. $this->addError($attribute, '不支持PayStack方式支付');
  193. return;
  194. }
  195. // 所选支付方式必须是商品分类支持的类型
  196. $categoryType = array_column(ShopGoods::CATEGORY_TYPE, NULL, 'id');
  197. // 商品类型
  198. $currCategoryType = $goodsCategoryType[0];
  199. if (!array_key_exists($currCategoryType, $categoryType)) {
  200. $this->addError($attribute, '商品分类错误');
  201. return;
  202. }
  203. $sellType = $categoryType[$currCategoryType]['sell_type'] ?? [];
  204. if (!$sellType || !in_array($this->payType, array_column($sellType, 'label'))) {
  205. $this->addError($attribute, '支付方式错误3');
  206. }
  207. }
  208. /**
  209. * 校验类型
  210. * @param $attribute
  211. */
  212. public function isStatus($attribute){
  213. if($this->type && !in_array($this->type, \Yii::$app->params['orderStatus'])){
  214. $this->addError($attribute, '订单状态类型错误');
  215. return ;
  216. }
  217. if ($this->scenario == 'adminStatus'){
  218. if ($this->status == $this->_model['STATUS']) {
  219. $this->addError($attribute, '订单状态没有改变');
  220. return ;
  221. }
  222. if($this->status == \Yii::$app->params['orderStatus']['notPaid'] && $this->_model['STATUS'] >= \Yii::$app->params['orderStatus']['delivery']) {
  223. $this->addError($attribute, '订单已经进入物流状态不能改为未支付');
  224. return ;
  225. }
  226. elseif($this->status == \Yii::$app->params['orderStatus']['paid'] && $this->_model['STATUS'] >= \Yii::$app->params['orderStatus']['cancel']) {
  227. $this->addError($attribute, '订单已失效不能处理');
  228. return ;
  229. }
  230. elseif($this->status == \Yii::$app->params['orderStatus']['delivery']) {
  231. $this->addError($attribute, '订单不能单独处理为物流状态');
  232. return ;
  233. }
  234. elseif($this->status == \Yii::$app->params['orderStatus']['complete'] && $this->_model['STATUS'] > \Yii::$app->params['orderStatus']['cancel']) {
  235. $this->addError($attribute, '订单已失效不能处理');
  236. return ;
  237. }
  238. elseif($this->status == \Yii::$app->params['orderStatus']['cancel']) {
  239. if($this->_model['STATUS'] == \Yii::$app->params['orderStatus']['complete']) {
  240. $this->addError($attribute, '订单已完成不能取消');
  241. return ;
  242. }
  243. if($this->_model['STATUS'] == \Yii::$app->params['orderStatus']['del']) {
  244. $this->addError($attribute, '订单已删除不能取消');
  245. return ;
  246. }
  247. }
  248. elseif($this->status == \Yii::$app->params['orderStatus']['del']) {
  249. if($this->_model['STATUS'] == \Yii::$app->params['orderStatus']['complete']) {
  250. $this->addError($attribute, '订单已完成不能删除');
  251. return ;
  252. }
  253. }
  254. }
  255. }
  256. /**
  257. * 校验PayStack支付,更新订单状态.同步到正式订单.
  258. * @throws Exception
  259. */
  260. public function verifyPayStack(): ?ApproachOrder
  261. {
  262. if (!$this->validate()) {
  263. return null;
  264. }
  265. // 调用PayStack支付校验
  266. LoggerTool::info([$this->note['reference'], $this->note]);
  267. $payload = PayStack::transactionVerify($this->note['reference']);
  268. LoggerTool::info($payload);
  269. if ($payload['status'] !== true) {
  270. throw new Exception(Form::formatErrorsForApi($payload['message']));
  271. }
  272. if ($payload['data']['amount'] != $this->_model->PAY_AMOUNT * 100) {
  273. throw new Exception(Form::formatErrorsForApi('支付金额与订单金额不符'));
  274. }
  275. $db = \Yii::$app->db;
  276. $transaction = $db->beginTransaction();
  277. try {
  278. // 更新准订单状态为已支付
  279. $this->_model->STATUS = $this->status;
  280. $this->_model->NOTE = json_encode($this->note);
  281. $this->_model->PAY_AT = Date::utcToTime($this->note['paid_at']);
  282. $this->_model->EMAIL = $this->note['email'];
  283. if (!$this->_model->save()) {
  284. throw new Exception(Form::formatErrorsForApi($this->_model->getErrors()));
  285. }
  286. // 更新订单商品的支付Email
  287. ApproachOrderGoods::updateAll(['EMAIL' => $this->note['email']], 'ORDER_SN = :ORDER_SN', [':ORDER_SN' => $this->sn]);
  288. // 同步准订单到正式订单
  289. Order::insertOne($this->_model->toArray());
  290. // 同步准订单商品到正式订单商品
  291. $approachOrderGoods = ApproachOrderGoods::findAllAsArray('ORDER_SN = :ORDER_SN', [':ORDER_SN' => $this->sn]);
  292. foreach ($approachOrderGoods as &$approachOrderGood) {
  293. $approachOrderGood['EMAIL'] = $this->email;
  294. }
  295. OrderGoods::batchInsert($approachOrderGoods);
  296. // 同步报单
  297. $approachDecOrder = ApproachDecOrder::findOneAsArray('ORDER_SN = :ORDER_SN', [':ORDER_SN' => $this->sn]);
  298. if ($approachDecOrder) {
  299. unset($approachDecOrder['STATUS']);
  300. // 同步报单
  301. DecOrder::insertOne($approachDecOrder);
  302. // 会员升级 报单类型:2会员升级单
  303. if ($approachDecOrder['DETAIL_TYPE'] == 2) {
  304. // 为被升级人进行升级操作
  305. $decLevelLog = new DecLevelLog();
  306. $decLog = [
  307. 'userId' => $approachDecOrder['TO_USER_ID'],//会员ID
  308. 'fromId' => $approachDecOrder['ORI_LV'], // 变动前的级别
  309. 'levelId' => $approachDecOrder['UPGRADE_LV'],// 变动后的级别
  310. 'actionId' => $approachDecOrder['USER_ID'],
  311. 'remark' => $approachDecOrder['REMARK'],
  312. 'lvPv' => $this->_model->PV,
  313. ];
  314. $modifyDecLv = $decLevelLog->frontendChange($decLog);
  315. if (empty($modifyDecLv)) {
  316. $transaction->rollBack();
  317. throw new Exception("Failed to upgrade for member");//为会员升级失败
  318. }
  319. }
  320. }
  321. // 删除中间表
  322. ApproachOrder::deleteAll('SN = :SN', [':SN' => $this->sn]);
  323. ApproachOrderGoods::deleteAll('ORDER_SN = :ORDER_SN', [':ORDER_SN' => $this->sn]);
  324. ApproachDecOrder::deleteAll('ORDER_SN = :ORDER_SN', [':ORDER_SN' => $this->sn]);
  325. $transaction->commit();
  326. } catch (Exception $e) {
  327. $transaction->rollBack();
  328. $this->addError('edit', $e->getFile() . ' ' . $e->getMessage());
  329. return null;
  330. }
  331. return $this->_model;
  332. }
  333. /**
  334. * 复销
  335. * @throws Exception
  336. * @throws \yii\db\Exception
  337. */
  338. public function add(){
  339. if(!$this->validate()){
  340. return null;
  341. }
  342. $ids = $this->goodsId;
  343. $totalAmount = 0;
  344. $totalPv = 0;
  345. $totalAmountStandard = 0;
  346. $goodsType = ShopGoods::GOODS_TYPE;
  347. $exchangeRate = floatval(Cache::getSystemConfig()['exchangeRate']['VALUE'] ?? 0); // 汇率
  348. foreach ($this->goodsNum as $k => $v) {
  349. if ($v) {
  350. $goods = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1',[':ID'=> $ids[$k]]);
  351. if($goods['STORE_NUMS']>0){
  352. if ($goods['TYPE'] == 1 || $goods['TYPE'] == 2) {
  353. $discount = $goodsType[$goods['TYPE']]['discount'];
  354. $realPrice = $goods['SELL_PRICE'] * $discount/100;
  355. $realPv = $goods['PRICE_PV'] * $discount/100;
  356. $realPriceStandard = $goods['SELL_PRICE_STANDARD'] * $discount/100;
  357. } else {
  358. $discount = $goods['SELL_DISCOUNT'];
  359. $realPrice = $goods['SELL_PRICE'] * $discount;
  360. $realPv = $goods['PRICE_PV'] * $discount;
  361. $realPriceStandard = $goods['SELL_PRICE_STANDARD'] * $discount;
  362. }
  363. $totalAmount += $realPrice * intval($v);
  364. $totalPv += $realPv * intval($v);
  365. $totalAmountStandard += $realPriceStandard * intval($v);
  366. $this->_orderGoods[] = [
  367. 'GOODS_ID' => $goods['ID'],
  368. 'PRICE' => $goods['SELL_PRICE'],
  369. 'PV' => $goods['PRICE_PV'],
  370. 'REAL_PRICE' => $realPrice,
  371. 'REAL_PV' => $realPv,
  372. 'POINT' => $goods['POINT'],
  373. 'BUY_NUMS' => intval($v),
  374. 'TAX_RATE' => $goods['TAX_RATE'],
  375. 'SKU_CODE' => $goods['GOODS_NO'],
  376. 'GOODS_TITLE' => $goods['GOODS_NAME'],
  377. 'CATEGORY_TYPE' => $goods['CATEGORY_TYPE'],
  378. 'PAY_TYPE' => $this->payType,
  379. 'EMAIL' => $this->email,
  380. 'STANDARD_PRICE' => $goods['SELL_PRICE_STANDARD'],
  381. 'REAL_STANDARD_PRICE' => $realPriceStandard,
  382. 'EXCHANGE_RATE' => $exchangeRate,
  383. ];
  384. }
  385. }
  386. }
  387. // 汇率
  388. $exchangeRate = floatval(Cache::getSystemConfig()['exchangeRate']['VALUE'] ?? 0);
  389. // 运费.奈拉
  390. $freight = floatval(Cache::getSystemConfig()['freight']['VALUE'] ?? 0);
  391. // 普通商品免运费阈值.奈拉
  392. $freeShipping = floatval(Cache::getSystemConfig()['freeShipping']['VALUE'] ?? 0);
  393. $this->_decAmount = $totalAmount;
  394. $this->_decPv = $totalPv;
  395. $this->_freight = ($totalAmount >= $freeShipping) ? 0 : $freight;
  396. if($this->_address['PROVINCE']==1){
  397. $this->_freight = 0;
  398. }
  399. $this->_payAmount = $this->_decAmount + $this->_freight;
  400. $this->_decAmountStandard = $totalAmountStandard;
  401. $this->_standardAmount = $this->_decAmountStandard + $this->_freight;
  402. $db = \Yii::$app->db;
  403. $transaction = $db->beginTransaction();
  404. try {
  405. //写入订单
  406. if (!$orderResult = $this->addOrder()) {
  407. throw new Exception(Form::formatErrorsForApi($orderResult->getErrors()));
  408. }
  409. $transaction->commit();
  410. return $orderResult;
  411. }catch (\Exception $e){
  412. $transaction->rollBack();
  413. $this->addError('add', $e->getMessage());
  414. return null;
  415. }
  416. }
  417. /**
  418. * 复销订单
  419. * @throws Exception
  420. */
  421. public function addOrder()
  422. {
  423. $periodObj = Period::instance();
  424. $nowPeriodNum = $periodObj->getNowPeriodNum();
  425. $nowCalcMonth = $periodObj->getYearMonth($nowPeriodNum);
  426. $userId = \Yii::$app->user->id;
  427. $userName = Info::getUserNameByUserId($userId);
  428. $userRealName = Info::getUserRealNameByUserId($userId);
  429. $userMobile = Info::getUserMobileByUserId($userId);
  430. $userEmail = Info::getUserEmailByUserId($userId);
  431. $exchangeRate = floatval(Cache::getSystemConfig()['exchangeRate']['VALUE'] ?? 0);
  432. // 加入订单信息
  433. if ($this->_address['PROVINCE'] != 1) {
  434. $warehouse = Region::getWarehouseByCode($this->_address['PROVINCE']);//仓库
  435. if (!$warehouse) {
  436. // throw new Exception('地区2暂时不支持配送,具体联系客服');
  437. }
  438. }else{
  439. $warehouse = '01';
  440. }
  441. $_hasPV = $this->_decPv;
  442. $ordNo = $this->_generateSn();
  443. $orderModel = new ApproachOrder();
  444. $orderModel->SN = 'OS' . $ordNo;
  445. $orderModel->DEC_SN = 'DS' . $ordNo;
  446. $orderModel->ORDER_TYPE = $this->type;
  447. $orderModel->USER_ID = $userId;
  448. $orderModel->USER_NAME = $userName;
  449. $orderModel->ORDER_AMOUNT = $this->_decAmount;
  450. $orderModel->PV = $_hasPV;
  451. $orderModel->PAY_AMOUNT = $this->_payAmount;
  452. $orderModel->PAY_PV = $_hasPV; // 兑换积分不能算业绩
  453. $orderModel->PAY_AT = 0;
  454. $orderModel->PAY_TYPE = $this->payType;
  455. $orderModel->PERIOD_NUM = $nowPeriodNum;
  456. $orderModel->P_CALC_MONTH = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
  457. $orderModel->FREIGHT = $this->_freight;
  458. $orderModel->PAY_FREIGHT = $this->_freight;
  459. $orderModel->CONSIGNEE = $this->_address['CONSIGNEE'];
  460. $orderModel->MOBILE = $this->_address['MOBILE'];
  461. $orderModel->PROVINCE = $this->_address['PROVINCE'];
  462. // $orderModel->CITY = $this->_address['CITY'];
  463. // $orderModel->COUNTY = $this->_address['COUNTY'];
  464. $orderModel->LGA_NAME = $this->_address['LGA_NAME'];
  465. $orderModel->CITY_NAME = $this->_address['CITY_NAME'];
  466. $orderModel->ADDRESS = $this->_address['ADDRESS'];
  467. $orderModel->FRONT_REMARK = $this->remark;
  468. $orderModel->WAREHOUSE = $warehouse;
  469. $orderModel->STATUS = \Yii::$app->params['orderStatus']['notPaid']['value'];
  470. $orderModel->CREATED_AT = Date::nowTime();
  471. $orderModel->CREATE_USER = $userName;
  472. $orderModel->EMAIL = $userEmail?$userEmail:$userName.'@elken.net';
  473. $orderModel->ORDER_AMOUNT_STANDARD = $this->_decAmountStandard;
  474. $orderModel->PAY_AMOUNT_STANDARD = $this->_standardAmount;
  475. $orderModel->EXCHANGE_RATE = $exchangeRate;
  476. if($this->_address['PROVINCE']==1){
  477. $orderModel->EXPRESS_TYPE = 1;
  478. $orderModel->CONSIGNEE = $userRealName;
  479. $orderModel->MOBILE = $userMobile;
  480. $orderModel->PROVINCE = 1;
  481. $orderModel->CITY = 1;
  482. $orderModel->COUNTY = 1;
  483. $orderModel->ADDRESS = '';
  484. }
  485. if(!$orderModel->save()){
  486. $this->addErrors($orderModel->getErrors());
  487. return false;
  488. }
  489. // 加入商品到订单商品表
  490. foreach($this->_orderGoods as $key=>$value) {
  491. $this->_orderGoods[$key]['ORDER_SN'] = $orderModel->SN;
  492. $this->_orderGoods[$key]['P_CALC_MONTH'] = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
  493. }
  494. ApproachOrderGoods::batchInsert($this->_orderGoods);
  495. // TODO: 记录流水
  496. return $orderModel;
  497. }
  498. /**
  499. * 生成流水号
  500. * @return string
  501. */
  502. private function _generateSn() {
  503. return Date::today('Ymd') . $this->_random(10, 1);
  504. }
  505. /**
  506. * 生成随机数
  507. * @param $length
  508. * @param int $numeric
  509. * @return string
  510. */
  511. private function _random($length, $numeric = 0) {
  512. $seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
  513. $seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed));
  514. $hash = '';
  515. $max = strlen($seed) - 1;
  516. for ($i = 0; $i < $length; $i++) {
  517. $hash .= $seed[mt_rand(0, $max)];
  518. }
  519. return $hash;
  520. }
  521. }