Core.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Code\Lib;
  3. use Dever;
  4. class Core
  5. {
  6. public function createCode($product, $cate_id, $product_id, $type = 1, $num = 1)
  7. {
  8. if ($product_id > 0) {
  9. Dever::setInput('set_product_id', $product_id);
  10. }
  11. //$data['product'] = $product;
  12. $data['cate_id'] = $cate_id;
  13. $data['product_id'] = $product_id;
  14. $data['type'] = $type;
  15. $db = Dever::db('code/info');
  16. if ($product_id > 0) {
  17. $code = $db->insert($data, $num);
  18. $code = $this->view($code, true);
  19. return $code;
  20. } else {
  21. for ($i = 0; $i < $num; $i++) {
  22. $data['i'] = $i;
  23. $id = $db->insert($data);
  24. if ($id) {
  25. $code = $this->view($id, false);
  26. $db->update(array('code' => $code, 'where_id' => $id));
  27. }
  28. }
  29. return $code;
  30. }
  31. }
  32. public function view($id, $state)
  33. {
  34. if ($state) {
  35. $code = Dever::uid($id * 10000000);
  36. $code = 'M' . $code;
  37. } else {
  38. $code = Dever::rand(4);
  39. $code = 'T' . $code . $id;
  40. }
  41. return $code;
  42. }
  43. }